Пример #1
0
 public Task RunPluginTaskAsyncThrowsNotsupported()
 {
     using (TestHostContext tc = CreateTestContext())
     {
         Tracing trace = tc.GetTrace();
         var     agentPluginManager = new AgentPluginManager();
         agentPluginManager.Initialize(tc);
         var executionContext = CreateTestExecutionContext(tc);
         return(Assert.ThrowsAsync <NotSupportedException>(() =>
                                                           agentPluginManager.RunPluginTaskAsync(executionContext, "invalid.plugin", new Dictionary <string, string>(), new Dictionary <string, string>(), null, null)
                                                           ));
     }
 }
Пример #2
0
        public void GeneratePluginExecutionContextHostInfoTest()
        {
            using (TestHostContext tc = CreateTestContext())
            {
                Tracing trace = tc.GetTrace();
                var     agentPluginManager = new AgentPluginManager();
                agentPluginManager.Initialize(tc);

                var inputs = new Dictionary <string, string>()
                {
                    { "input1", "foo" },
                    { "input2", tc.GetDirectory(WellKnownDirectory.Work) },
                };

                var variables = new Dictionary <string, VariableValue>()
                {
                    { "variable1", "foo" },
                    { "variable2", tc.GetDirectory(WellKnownDirectory.Work) },
                };

                var taskVariables = new Dictionary <string, VariableValue>()
                {
                    { "taskVariable1", "foo" },
                    { "taskVariable2", tc.GetDirectory(WellKnownDirectory.Work) },
                };
                var executionContext = CreateTestExecutionContext(tc, variables: variables, taskVariables: taskVariables);

                var pluginContext = agentPluginManager.GeneratePluginExecutionContext(executionContext, inputs, executionContext.Variables);
                Assert.True(pluginContext != null, "PluginContext for Host Step Target is not null");
                // inputs should match exactly for Host Step Targets
                Assert.True(inputs.All(e => pluginContext.Inputs.Contains(e)));
                // variables should match exactly for Host Step Targets
                Assert.True(variables.All(e => pluginContext.Variables.Contains(e)));
                // task variables should match exactly for Host Step Targets
                Assert.True(taskVariables.All(e => pluginContext.TaskVariables.Contains(e)));
            }
        }
        public void SimpleTests()
        {
            using (TestHostContext tc = CreateTestContext())
            {
                Tracing trace = tc.GetTrace();
                var     agentPluginManager = new AgentPluginManager();
                agentPluginManager.Initialize(tc);

                List <AgentPluginTaskTest> tests = new List <AgentPluginTaskTest>
                {
                    new AgentPluginTaskTest()
                    {
                        Name                = "Checkout Task",
                        TaskGuid            = Pipelines.PipelineConstants.CheckoutTask.Id,
                        ExpectedTaskPlugins = new List <string>
                        {
                            "Agent.Plugins.Repository.CheckoutTask, Agent.Plugins",
                            "Agent.Plugins.Repository.CleanupTask, Agent.Plugins",
                        }
                    },
                    new AgentPluginTaskTest()
                    {
                        Name                = "Download Pipline Artifact Task",
                        TaskGuid            = PipelineArtifactPluginConstants.DownloadPipelineArtifactTaskId,
                        ExpectedTaskPlugins = new List <string>
                        {
                            "Agent.Plugins.PipelineArtifact.DownloadPipelineArtifactTask, Agent.Plugins",
                            "Agent.Plugins.PipelineArtifact.DownloadPipelineArtifactTaskV1, Agent.Plugins",
                            "Agent.Plugins.PipelineArtifact.DownloadPipelineArtifactTaskV1_1_0, Agent.Plugins",
                            "Agent.Plugins.PipelineArtifact.DownloadPipelineArtifactTaskV1_1_1, Agent.Plugins",
                            "Agent.Plugins.PipelineArtifact.DownloadPipelineArtifactTaskV1_1_2, Agent.Plugins",
                            "Agent.Plugins.PipelineArtifact.DownloadPipelineArtifactTaskV1_1_3, Agent.Plugins",
                            "Agent.Plugins.PipelineArtifact.DownloadPipelineArtifactTaskV2_0_0, Agent.Plugins",
                        }
                    },
                    new AgentPluginTaskTest()
                    {
                        Name                = "Publish Pipeline Artifact Task",
                        TaskGuid            = PipelineArtifactPluginConstants.PublishPipelineArtifactTaskId,
                        ExpectedTaskPlugins = new List <string>
                        {
                            "Agent.Plugins.PipelineArtifact.PublishPipelineArtifactTask, Agent.Plugins",
                            "Agent.Plugins.PipelineArtifact.PublishPipelineArtifactTaskV1, Agent.Plugins",
                            "Agent.Plugins.PipelineArtifact.PublishPipelineArtifactTaskV0_140_0, Agent.Plugins"
                        }
                    },
                    new AgentPluginTaskTest()
                    {
                        Name                = "Pipeline Cache Task",
                        TaskGuid            = PipelineCachePluginConstants.CacheTaskId,
                        ExpectedTaskPlugins = new List <string>
                        {
                            "Agent.Plugins.PipelineCache.SavePipelineCacheV0, Agent.Plugins",
                            "Agent.Plugins.PipelineCache.RestorePipelineCacheV0, Agent.Plugins",
                        }
                    },
                };

                foreach (var test in tests)
                {
                    test.RunTest(agentPluginManager);
                }
            }
        }
Пример #4
0
        public void GeneratePluginExecutionContextContainerInfoTest()
        {
            var dockerContainer = new Pipelines.ContainerResource()
            {
                Alias = "vsts_container_preview",
                Image = "foo"
            };

            using (TestHostContext tc = CreateTestContext())
            {
                Tracing trace = tc.GetTrace();
                var     agentPluginManager = new AgentPluginManager();
                agentPluginManager.Initialize(tc);
                var containerInfo     = tc.CreateContainerInfo(dockerContainer, isJobContainer: false);
                var containerWorkPath = "/__w";
                if (TestUtil.IsWindows())
                {
                    containerWorkPath = "C:\\__w";
                }
                var inputs = new Dictionary <string, string>()
                {
                    { "input1", "foo" },
                    { "input2", containerWorkPath },
                    { "input3", tc.GetDirectory(WellKnownDirectory.Work) },
                };

                var expectedInputs = new Dictionary <string, string>()
                {
                    { "input1", "foo" },
                    { "input2", tc.GetDirectory(WellKnownDirectory.Work) },
                    { "input3", tc.GetDirectory(WellKnownDirectory.Work) },
                };

                var variables = new Dictionary <string, VariableValue>()
                {
                    { "variable1", "foo" },
                    { "variable2", containerWorkPath },
                    { "variable3", tc.GetDirectory(WellKnownDirectory.Work) },
                };

                var expectedVariables = new Dictionary <string, VariableValue>()
                {
                    { "variable1", "foo" },
                    { "variable2", tc.GetDirectory(WellKnownDirectory.Work) },
                    { "variable3", tc.GetDirectory(WellKnownDirectory.Work) },
                };

                var taskVariables = new Dictionary <string, VariableValue>()
                {
                    { "taskVariable1", "foo" },
                    { "taskVariable2", containerWorkPath },
                    { "taskVariable3", tc.GetDirectory(WellKnownDirectory.Work) },
                };

                var expectedTaskVariables = new Dictionary <string, VariableValue>()
                {
                    { "taskVariable1", "foo" },
                    { "taskVariable2", tc.GetDirectory(WellKnownDirectory.Work) },
                    { "taskVariable3", tc.GetDirectory(WellKnownDirectory.Work) },
                };

                var executionContext = CreateTestExecutionContext(tc, stepTarget: containerInfo, variables: variables, taskVariables: taskVariables);

                var pluginContext = agentPluginManager.GeneratePluginExecutionContext(executionContext, inputs, executionContext.Variables);
                Assert.True(pluginContext != null, "PluginContext for Container Step Target is not null");
                Assert.True(expectedInputs.All(e => pluginContext.Inputs.Contains(e)));
                Assert.True(expectedVariables.All(e => pluginContext.Variables.Contains(e)));
                Assert.True(expectedTaskVariables.All(e => pluginContext.TaskVariables.Contains(e)));
            }
        }