Beispiel #1
0
        public void ReplacesMultipleMacroInstances()
        {
            try
            {
                // Arrange.
                Setup();
                const string Directory  = "Some directory";
                Definition   definition = new Definition()
                {
                    Directory = Directory
                };
                NodeHandlerData node = new NodeHandlerData()
                {
                    Target = @"$(CuRrEnTdIrEcToRy)$(CuRrEnTdIrEcToRy)\Some node target",
                };

                // Act.
                node.ReplaceMacros(_hc, definition);

                // Assert.
                Assert.Equal($@"{Directory}{Directory}\Some node target", node.Target);
            }
            finally
            {
                Teardown();
            }
        }
        public void MatchesPlatform()
        {
            try
            {
                // Arrange.
                Setup();
#if OS_WINDOWS
                const string Platform = "WiNdOwS";
#else
                // TODO: What to do here?
                const string Platform = "";
                if (string.IsNullOrEmpty(Platform))
                {
                    return;
                }
#endif
                HandlerData data = new NodeHandlerData()
                {
                    Platforms = new[] { Platform }
                };

                // Act/Assert.
                Assert.True(data.PreferredOnCurrentPlatform());
            }
            finally
            {
                Teardown();
            }
        }
Beispiel #3
0
        public void ReplacesMacrosAndPreventsInfiniteRecursion()
        {
            try
            {
                // Arrange.
                Setup();
                string     directory  = "$(currentdirectory)$(currentdirectory)";
                Definition definition = new Definition()
                {
                    Directory = directory
                };
                NodeHandlerData node = new NodeHandlerData()
                {
                    Target = @"$(currentDirectory)\Some node target",
                };

                // Act.
                node.ReplaceMacros(_hc, definition);

                // Assert.
                Assert.Equal($@"{directory}\Some node target", node.Target);
            }
            finally
            {
                Teardown();
            }
        }
        public void ReplacesMacros()
        {
            try
            {
                // Arrange.
                using (var tokenSource = new CancellationTokenSource())
                    using (var _hc = Setup(tokenSource))
                    {
                        const string Directory  = "Some directory";
                        Definition   definition = new Definition()
                        {
                            Directory = Directory
                        };
                        NodeHandlerData node = new NodeHandlerData()
                        {
                            Target           = @"$(CuRrEnTdIrEcToRy)\Some node target",
                            WorkingDirectory = @"$(CuRrEnTdIrEcToRy)\Some node working directory",
                        };
                        ProcessHandlerData process = new ProcessHandlerData()
                        {
                            ArgumentFormat   = @"$(CuRrEnTdIrEcToRy)\Some process argument format",
                            Target           = @"$(CuRrEnTdIrEcToRy)\Some process target",
                            WorkingDirectory = @"$(CuRrEnTdIrEcToRy)\Some process working directory",
                        };

                        // Act.
                        node.ReplaceMacros(_hc, definition);
                        process.ReplaceMacros(_hc, definition);

                        // Assert.
                        Assert.Equal($@"{Directory}\Some node target", node.Target);
                        Assert.Equal($@"{Directory}\Some node working directory", node.WorkingDirectory);
                        Assert.Equal($@"{Directory}\Some process argument format", process.ArgumentFormat);
                        Assert.Equal($@"{Directory}\Some process target", process.Target);
                        Assert.Equal($@"{Directory}\Some process working directory", process.WorkingDirectory);
                    }
            }
            finally
            {
                Teardown();
            }
        }
Beispiel #5
0
 public void MatchesPlatform()
 {
     try
     {
         // Arrange.
         Setup();
         HandlerData data = new NodeHandlerData()
         {
             Platforms = new[] { "WiNdOwS" }
         };
         // Act/Assert.
         Assert.True(data.PreferredOnPlatform(PlatformUtil.OS.Windows));
         Assert.False(data.PreferredOnPlatform(PlatformUtil.OS.Linux));
         Assert.False(data.PreferredOnPlatform(PlatformUtil.OS.OSX));
     }
     finally
     {
         Teardown();
     }
 }
Beispiel #6
0
 public void DoesNotMatchPlatform()
 {
     try
     {
         // Arrange.
         Setup();
         HandlerData data = new NodeHandlerData()
         {
             Platforms = new string[] { "nosuch" }
         };
         // Act/Assert.
         Assert.False(data.PreferredOnPlatform(PlatformUtil.OS.Windows));
         Assert.False(data.PreferredOnPlatform(PlatformUtil.OS.Linux));
         Assert.False(data.PreferredOnPlatform(PlatformUtil.OS.OSX));
     }
     finally
     {
         Teardown();
     }
 }
 public void MatchesPlatform()
 {
     try
     {
         // Arrange.
         using (var tokenSource = new CancellationTokenSource())
             using (var _hc = Setup(tokenSource))
             {
                 HandlerData data = new NodeHandlerData()
                 {
                     Platforms = new[] { "WiNdOwS" }
                 };
                 // Act/Assert.
                 Assert.True(data.PreferredOnPlatform(PlatformUtil.OS.Windows));
                 Assert.False(data.PreferredOnPlatform(PlatformUtil.OS.Linux));
                 Assert.False(data.PreferredOnPlatform(PlatformUtil.OS.OSX));
             }
     }
     finally
     {
         Teardown();
     }
 }
        public void DoesNotMatchPlatform()
        {
            try
            {
                // Arrange.
                Setup();
#if !OS_WINDOWS
                const string Platform = "windows";
#else
                const string Platform = "nosuch"; // TODO: What to do here?
#endif
                HandlerData data = new NodeHandlerData()
                {
                    Platforms = new string[] { Platform }
                };

                // Act/Assert.
                Assert.False(data.PreferredOnCurrentPlatform());
            }
            finally
            {
                Teardown();
            }
        }
Beispiel #9
0
        public void GetHandlerHostOnlyTests()
        {
            var nodeData = new NodeHandlerData()
            {
                Platforms = new string[] { "linux", "osx" }
            };
            var nodeOnlyExecutionData = new ExecutionData();

            nodeOnlyExecutionData.Node = nodeData;
            var powerShell3Data = new PowerShell3HandlerData()
            {
                Platforms = new string[] { "windows" }
            };
            var ps3OnlyExecutionData = new ExecutionData();

            ps3OnlyExecutionData.PowerShell3 = powerShell3Data;
            var mixedExecutionData = new ExecutionData();

            mixedExecutionData.PowerShell3 = powerShell3Data;
            mixedExecutionData.Node        = nodeData;


            foreach (var test in new GetHandlerTest[] {
                new GetHandlerTest()
                {
                    Name = "Empty Test", Input = null, Expected = null, HostOS = PlatformUtil.OS.Windows
                },
                new GetHandlerTest()
                {
                    Name = "Node Only on Windows", Input = nodeOnlyExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.Windows
                },
                new GetHandlerTest()
                {
                    Name = "Node Only on Linux", Input = nodeOnlyExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.Linux
                },
                new GetHandlerTest()
                {
                    Name = "Node Only on OSX", Input = nodeOnlyExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.OSX
                },
                new GetHandlerTest()
                {
                    Name = "PowerShell3 Only on Windows", Input = ps3OnlyExecutionData, Expected = powerShell3Data, HostOS = PlatformUtil.OS.Windows
                },
                new GetHandlerTest()
                {
                    Name = "PowerShell3 Only on Linux", Input = ps3OnlyExecutionData, Expected = powerShell3Data, HostOS = PlatformUtil.OS.Linux
                },
                new GetHandlerTest()
                {
                    Name = "PowerShell3 Only on OSX", Input = ps3OnlyExecutionData, Expected = powerShell3Data, HostOS = PlatformUtil.OS.OSX
                },
                new GetHandlerTest()
                {
                    Name = "Mixed on Windows", Input = mixedExecutionData, Expected = powerShell3Data, HostOS = PlatformUtil.OS.Windows
                },
                new GetHandlerTest()
                {
                    Name = "Mixed on Linux", Input = mixedExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.Linux
                },
                new GetHandlerTest()
                {
                    Name = "Mixed on OSX", Input = mixedExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.OSX
                },
            })
            {
                using (TestHostContext hc = CreateTestContext(test.Name))
                {
                    test.RunTest(hc);
                }
            }
        }
Beispiel #10
0
        public void GetHandlerContainerTargetPreferNodeDisabledTests()
        {
            var nodeData = new NodeHandlerData();
            var nodeOnlyExecutionData = new ExecutionData();

            nodeOnlyExecutionData.Node = nodeData;
            var powerShell3Data = new PowerShell3HandlerData()
            {
                Platforms = new string[] { "windows" }
            };
            var ps3OnlyExecutionData = new ExecutionData();

            ps3OnlyExecutionData.PowerShell3 = powerShell3Data;
            var mixedExecutionData = new ExecutionData();

            mixedExecutionData.Node        = nodeData;
            mixedExecutionData.PowerShell3 = powerShell3Data;

            ContainerInfo containerInfo = new ContainerInfo()
            {
            };

            foreach (var test in new GetHandlerTest[] {
                new GetHandlerTest()
                {
                    Name = "Empty Test", Input = null, Expected = null, HostOS = PlatformUtil.OS.Windows, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "Node Only on Windows", Input = nodeOnlyExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.Windows, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "Node Only on Linux", Input = nodeOnlyExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.Linux, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "Node Only on OSX", Input = nodeOnlyExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.OSX, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "PowerShell3 Only on Windows", Input = ps3OnlyExecutionData, Expected = powerShell3Data, HostOS = PlatformUtil.OS.Windows, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "PowerShell3 Only on Linux", Input = ps3OnlyExecutionData, Expected = powerShell3Data, HostOS = PlatformUtil.OS.Linux, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "PowerShell3 Only on OSX", Input = ps3OnlyExecutionData, Expected = powerShell3Data, HostOS = PlatformUtil.OS.OSX, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "Mixed on Windows", Input = mixedExecutionData, Expected = powerShell3Data, HostOS = PlatformUtil.OS.Windows, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "Mixed on Linux", Input = mixedExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.Linux, StepTarget = containerInfo
                },
                new GetHandlerTest()
                {
                    Name = "Mixed on OSX", Input = mixedExecutionData, Expected = nodeData, HostOS = PlatformUtil.OS.OSX, StepTarget = containerInfo
                },
            })
            {
                var variables = new Dictionary <string, VariableValue>();
                variables.Add("agent.preferPowerShellOnContainers", "true");
                using (TestHostContext hc = CreateTestContext(test.Name))
                {
                    test.RunTest(hc, variables);
                    Environment.SetEnvironmentVariable("AGENT_PREFER_POWERSHELL_ON_CONTAINERS", "true");
                    test.RunTest(hc);
                    Environment.SetEnvironmentVariable("AGENT_PREFER_POWERSHELL_ON_CONTAINERS", null);
                }
            }
        }