public void Fingerprint_FileRelative()
        {
            string workingDir = Path.GetDirectoryName(path1);
            string relPath1   = Path.GetFileName(path1);
            string relPath2   = Path.GetFileName(path2);

            using (var hostContext = new TestHostContext(this))
            {
                var context = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                context.SetVariable(
                    "system.defaultworkingdirectory", // Constants.Variables.System.DefaultWorkingDirectory
                    workingDir,
                    isSecret: false);

                var segments = new[]
                {
                    $"{relPath1}",
                    $"{relPath2}",
                };

                Fingerprint f = FingerprintCreator.EvaluateKeyToFingerprint(context, directory, segments);

                var file1 = new FingerprintCreator.MatchedFile(relPath1, content1.Length, hash1.ToHex());
                var file2 = new FingerprintCreator.MatchedFile(relPath2, content2.Length, hash2.ToHex());

                Assert.Equal(2, f.Segments.Length);
                Assert.Equal(file1.GetHash(), f.Segments[0]);
                Assert.Equal(file2.GetHash(), f.Segments[1]);
            }
        }
 public void Fingerprint_ReservedFails()
 {
     using (var hostContext = new TestHostContext(this))
     {
         var context = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
         Assert.Throws <ArgumentException>(
             () => FingerprintCreator.EvaluateKeyToFingerprint(context, directory, new [] { "*" })
             );
         Assert.Throws <ArgumentException>(
             () => FingerprintCreator.EvaluateKeyToFingerprint(context, directory, new [] { "**" })
             );
     }
 }
 public void Fingerprint_ExcludeExactMatches()
 {
     using (var hostContext = new TestHostContext(this))
     {
         var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
         var segments = new[]
         {
             $"{Path.GetDirectoryName(path1)},!{path1}",
         };
         Assert.Throws <AggregateException>(
             () => FingerprintCreator.EvaluateKeyToFingerprint(context, directory, segments)
             );
     }
 }
Ejemplo n.º 4
0
        public void Fingerprint_Path_NoIncludePatterns()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var segments = new[]
                {
                    $"!**/{directory1Name},!**/{directory2Name}",
                };

                Assert.Throws <ArgumentException>(
                    () => FingerprintCreator.EvaluateToFingerprint(context, workspaceRoot, segments, FingerprintType.Path)
                    );
            }
        }
Ejemplo n.º 5
0
        public void Fingerprint_ExcludeExactMisses()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var segments = new[]
                {
                    $"{path1},!{path2}",
                };
                Fingerprint f = FingerprintCreator.EvaluateKeyToFingerprint(context, directory, segments);

                Assert.Equal(1, f.Segments.Length);
                Assert.Equal(FingerprintCreator.SummarizeString($"\nSHA256({Path.GetFileName(path1)})=[{content1.Length}]{hash1.ToHex()}"), f.Segments[0]);
            }
        }
        public void Fingerprint_Str()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var segments = new[]
                {
                    $"hello",
                };

                Fingerprint f = FingerprintCreator.EvaluateKeyToFingerprint(context, directory, segments);

                Assert.Equal(1, f.Segments.Length);
                Assert.Equal($"hello", f.Segments[0]);
            }
        }
Ejemplo n.º 7
0
        public void Fingerprint_Path_BacktracedGlobPattern()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context       = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var directoryInfo = new DirectoryInfo(workspaceRoot);
                var segments      = new[]
                {
                    $"{directoryInfo.Parent.FullName}/*",
                };

                Assert.Throws <AggregateException>(
                    () => FingerprintCreator.EvaluateToFingerprint(context, workspaceRoot, segments, FingerprintType.Path)
                    );
            }
        }
Ejemplo n.º 8
0
        public void Fingerprint_Path_NoMatches()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var segments = new[]
                {
                    $"**/{Guid.NewGuid().ToString()},!**/{directory2Name}"
                };

                // TODO: Should this really be throwing an exception?
                Assert.Throws <AggregateException>(
                    () => FingerprintCreator.EvaluateToFingerprint(context, workspaceRoot, segments, FingerprintType.Path)
                    );
            }
        }
        public void Fingerprint_ExcludeExactMisses()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var segments = new[]
                {
                    $"{path1},!{path2}",
                };
                Fingerprint f = FingerprintCreator.EvaluateKeyToFingerprint(context, directory, segments);

                Assert.Equal(1, f.Segments.Length);

                var matchedFile = new FingerprintCreator.MatchedFile(Path.GetFileName(path1), content1.Length, hash1.ToHex());
                Assert.Equal(matchedFile.GetHash(), f.Segments[0]);
            }
        }
Ejemplo n.º 10
0
        public void Fingerprint_Path_MultiplePathOutsidePipelineWorkspace()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context       = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var directoryInfo = new DirectoryInfo(workspaceRoot);
                var segments      = new[]
                {
                    directoryInfo.Parent.FullName,
                    directory1Name,
                };

                Assert.Throws <AggregateException>(
                    () => FingerprintCreator.EvaluateToFingerprint(context, workspaceRoot, segments, FingerprintType.Path)
                    );
            }
        }
Ejemplo n.º 11
0
        public void Fingerprint_Path_ExcludeGlobMatches()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var segments = new[]
                {
                    $"**/{directory1Name},!**/{directory2Name}",
                };

                Fingerprint f = FingerprintCreator.EvaluateToFingerprint(context, workspaceRoot, segments, FingerprintType.Path);
                Assert.Equal(
                    new[] { directory1Name },
                    f.Segments
                    );
            }
        }
Ejemplo n.º 12
0
        public void Fingerprint_Path_IncludeRelativePathMatches()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var segments = new[]
                {
                    directory1Name,
                    directory2Name
                };

                Fingerprint f = FingerprintCreator.EvaluateToFingerprint(context, workspaceRoot, segments, FingerprintType.Path);
                Assert.Equal(
                    new[] { directory1Name, directory2Name }.OrderBy(x => x),
                    f.Segments.OrderBy(x => x)
                    );
            }
        }
        public void Fingerprint_FileAbsolute()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context  = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var segments = new[]
                {
                    $"{path1}",
                    $"{path2}",
                };
                Fingerprint f = FingerprintCreator.EvaluateKeyToFingerprint(context, directory, segments);

                var file1 = new FingerprintCreator.MatchedFile(Path.GetFileName(path1), content1.Length, hash1.ToHex());
                var file2 = new FingerprintCreator.MatchedFile(Path.GetFileName(path2), content2.Length, hash2.ToHex());

                Assert.Equal(2, f.Segments.Length);
                Assert.Equal(file1.GetHash(), f.Segments[0]);
                Assert.Equal(file2.GetHash(), f.Segments[1]);
            }
        }
Ejemplo n.º 14
0
        public void Fingerprint_Path_SinglePathOutsidePipelineWorkspace()
        {
            using (var hostContext = new TestHostContext(this))
            {
                var context       = new AgentTaskPluginExecutionContext(hostContext.GetTrace());
                var directoryInfo = new DirectoryInfo(workspaceRoot);
                var segments      = new[]
                {
                    directoryInfo.Parent.FullName,
                };

                Fingerprint f = FingerprintCreator.EvaluateToFingerprint(context, workspaceRoot, segments, FingerprintType.Path);

                Assert.Equal(1, f.Segments.Count());
                Assert.Equal(
                    new[] { Path.GetRelativePath(workspaceRoot, directoryInfo.Parent.FullName) },
                    f.Segments
                    );
            }
        }
Ejemplo n.º 15
0
        public void Fingerprint_IsPath()
        {
            Action <string, bool> assertPath = (path, isPath) =>
                                               Assert.True(isPath == FingerprintCreator.IsPathyKeySegment(path), $"IsPathy({path}) should have returned {isPath}.");

            assertPath(@"''", false);
            assertPath(@"Windows_NT", false);
            assertPath(@"README.md", true);
            assertPath(@"This is a sentence.", false);
            assertPath(@"http://xkcd.com.", false);
            assertPath(@"""D:\README.md""", false);
            assertPath(@"D:\README.md", true);
            assertPath(@"D:\src\vsts-agent\_layout\_work\2\s/README.md", true);
            assertPath(@"D:\src\vsts-agent\_layout\_work\2\s/**/README.md", true);
            assertPath(@"/**/README.md,!./junk/**;./azure-pipelines.yml", true);
            assertPath(@"./**,!./.git/**", true);
            assertPath(@"/src/foo", true);
            assertPath(@"src/foo", true);

            // ones we don't feel great about
            assertPath(@"We should go to the store/mall", true);
        }
Ejemplo n.º 16
0
 .Select(p => FingerprintCreator.MakePathCanonical(
             DefaultWorkingDirectory,
             p))
 .ToArray();