public void Should_handle_single_rule_with_source_only() { List <ArtifactRule> pathRules = ArtifactRule.Parse("source=>"); ArtifactRule artifactRule = pathRules[0]; Assert.Equal("source", artifactRule.Source); Assert.Equal(string.Empty, artifactRule.Dest); }
public void ParseRule(string rule, bool include, string sourcePath, string archivePath, string dest) { var artifactRule = new ArtifactRule(0, null, rule); Assert.That(artifactRule.Include, Is.EqualTo(include), "Include"); Assert.That(artifactRule.SourcePath, Is.EqualTo(sourcePath), "SourcePath"); Assert.That(artifactRule.ArchivePath, Is.EqualTo(archivePath), "ArchivePath"); Assert.That(artifactRule.DestinationPath, Is.EqualTo(dest), "DestinationPath"); }
public void Should_handle_single_rule_with_whitespace_padding() { List <ArtifactRule> pathRules = ArtifactRule.Parse(" source => dest "); ArtifactRule artifactRule = pathRules[0]; Assert.Equal("source", artifactRule.Source); Assert.Equal("dest", artifactRule.Dest); }
public void Should_handle_single_rule_with_new_line() { List <ArtifactRule> pathRules = ArtifactRule.Parse("source=>dest" + Environment.NewLine); Assert.Equal(1, pathRules.Count); ArtifactRule artifactRule = pathRules[0]; Assert.Equal("source", artifactRule.Source); Assert.Equal("dest", artifactRule.Dest); }
public string GetJobs_DownloadFile(string rule, string file) { var artifactRule = new ArtifactRule(0, "http://example.com/download", rule); var jobs = artifactRule.GetJobs(file); Assert.That(jobs.Count, Is.EqualTo(1)); Assert.That(jobs[0], Is.TypeOf <DownloadFileJob>()); var downloadJob = jobs[0] as DownloadFileJob; Assert.That(downloadJob.Url, Is.EqualTo("http://example.com/download/" + file)); return(NormalizedPath(downloadJob.TargetFile)); }
public void Should_handle_multiple_rules() { List <ArtifactRule> pathRules = ArtifactRule.Parse("source=>dest" + Environment.NewLine + "source2=>dest2"); Assert.Equal(2, pathRules.Count); Assert.Equal("source", pathRules[0].Source); Assert.Equal("dest", pathRules[0].Dest); Assert.Equal("source2", pathRules[1].Source); Assert.Equal("dest2", pathRules[1].Dest); }
public void Should_handle_multiple_rules_with_left_side_only() { List <ArtifactRule> pathRules = ArtifactRule.Parse("source=>dest" + Environment.NewLine + "source2=>"); Assert.Equal(2, pathRules.Count); Assert.Equal("source", pathRules[0].Source); Assert.Equal("dest", pathRules[0].Dest); Assert.Equal("source2", pathRules[1].Source); Assert.Equal(string.Empty, pathRules[1].Dest); }
public void Should_encode_white_spaces() { string source = "Cwi.Core-2.10-dev.zip!/My Path/Cwi.Core.dll"; var expected = new File { ContentHref = source, Name = "Cwi.Core.dll" }; File file = ArtifactRule.ParseSource(source); Assert.Equal("Cwi.Core-2.10-dev.zip!/My%20Path/Cwi.Core.dll", file.ContentHref); }
private async Task <List <PathFilePair> > FetchFileListForArtifactRule(ArtifactRule artifactRule, Build build, string basePath) { var files = new List <PathFilePair>(); if (artifactRule.Source.EndsWith("!**") || artifactRule.Source.EndsWith("!/**")) { artifactRule.Source.Replace("!/**", "!**"); files.Add(new PathFilePair { File = artifactRule.CreateTeamCityFileReference(build.Href + "/artifacts/content/"), Path = Path.Combine(basePath, artifactRule.Dest) }); } else { if (artifactRule.Source.Contains("*") || artifactRule.Source.Contains("?")) { List <TeamCityApi.Domain.File> artifactFiles = new List <File>(); string[] paths = artifactRule.Source.Split('/'); string fileName = paths[paths.Length - 1]; string pathPart = artifactRule.Source.Replace(fileName, String.Empty); Console.WriteLine("Filename: {0}", fileName); Console.WriteLine("Path: {0} -> Source: {1}", pathPart, artifactRule.Source); artifactFiles.AddRange(await GetAllArtifactFiles(build, pathPart, fileName)); foreach (var artifactFile in artifactFiles) { artifactRule.Source = (string.IsNullOrWhiteSpace(pathPart) == false ? pathPart + "/" : "") + artifactFile.Name; files.Add(new PathFilePair { File = artifactRule.CreateTeamCityFileReference(build.Href + "/artifacts/content/"), Path = Path.Combine(basePath, artifactRule.Dest ?? "") }); } } else { files.Add(new PathFilePair { File = artifactRule.CreateTeamCityFileReference(build.Href + "/artifacts/content/"), Path = Path.Combine(basePath, artifactRule.Dest ?? "") }); } } return(files); }
private static List <ArtifactRule> GetArtifactRules(DependencyDefinition dependency) { Property artifactRulesProperty = dependency.Properties.Property.FirstOrDefault( x => x.Name.Equals("pathRules", StringComparison.InvariantCultureIgnoreCase)); if (artifactRulesProperty == null || string.IsNullOrWhiteSpace(artifactRulesProperty.Value)) { throw new Exception(string.Format("Missing or invalid Artifact dependency. ProjectId: {0}", dependency.SourceBuildConfig.ProjectId)); } List <ArtifactRule> artifactRules = ArtifactRule.Parse(artifactRulesProperty.Value); return(artifactRules); }
public void Extract_full_zip() { string source = "MyFile.zip!**"; var expected = new File { ContentHref = "MyFile.zip", Name = "MyFile.zip!**" }; File file = ArtifactRule.ParseSource(source); Assert.Equal(expected.ContentHref, file.ContentHref); Assert.Equal(expected.Name, file.Name); }
public void Root_file() { string source = "Cwi.Core.dll"; var expected = new File { ContentHref = source, Name = "Cwi.Core.dll" }; File file = ArtifactRule.ParseSource(source); Assert.Equal(expected.ContentHref, file.ContentHref); Assert.Equal(expected.Name, file.Name); }
public void Directory() { string source = "/bin/release"; var expected = new File { ChildrenHref = source, Name = "release" }; File file = ArtifactRule.ParseSource(source); Assert.Null(file.ContentHref); Assert.Equal(expected.ChildrenHref, file.ChildrenHref); Assert.Equal(expected.Name, file.Name); }
public void File_within_zip() { string source = "Cwi.Core-2.10-dev.zip!/Cwi.Core.dll"; //string source = "en-us/BIFInstall_*.msi"; //string source = "BIFLoader-2.9.7-dev.zip!**"; var expected = new File { ContentHref = source, Name = "Cwi.Core.dll" }; File file = ArtifactRule.ParseSource(source); Assert.Equal(expected.ContentHref, file.ContentHref); Assert.Equal(expected.Name, file.Name); }
public void GetJobs_ZipFile() { var artifactRule = new ArtifactRule(0, "http://example.com/download", "a.zip!a/b/c/*/.dll=>dlls"); var jobs = artifactRule.GetJobs("a.zip"); Assert.That(jobs.Count, Is.EqualTo(2)); Assert.That(jobs[0], Is.TypeOf <DownloadZipJob>()); var downloadJob = jobs[0] as DownloadZipJob; Assert.That(downloadJob.Url, Is.EqualTo("http://example.com/download/a.zip")); Assert.That(downloadJob.TargetFile, Is.EqualTo(Path("Downloads/a.zip"))); Assert.That(jobs[1], Is.TypeOf <UnzipFilesJob>()); var unzipJob = jobs[1] as UnzipFilesJob; Assert.That(unzipJob.ZipFile, Is.EqualTo(Path("Downloads/a.zip"))); Assert.That(unzipJob.SourcePath, Is.EqualTo("a/b/c/*/.dll")); Assert.That(unzipJob.DestinationPath, Is.EqualTo("dlls")); }
public string GetTarget(string rule, string fileName) { var artifactRule = new ArtifactRule(0, null, rule); return(NormalizedPath(artifactRule.GetTarget(fileName))); }
public bool FileIsMatch(string rule, string fileName) { var artifactRule = new ArtifactRule(0, null, rule); return(artifactRule.IsMatch(fileName)); }
public void Should_handle_empty_strings() { List <ArtifactRule> pathRules = ArtifactRule.Parse(string.Empty); Assert.Empty(pathRules); }
public void Should_handle_empty_with_line_breaks() { List <ArtifactRule> pathRules = ArtifactRule.Parse(Environment.NewLine); Assert.Empty(pathRules); }