public void TranslateContainerPathForImageOSTestsWindowsToLinux() { var dockerContainer = new Pipelines.ContainerResource() { Alias = "vsts_container_preview", Image = "foo" }; using (TestHostContext hc = CreateTestContext()) { ContainerInfo info = hc.CreateContainerInfo(dockerContainer, isJobContainer: false); info.ImageOS = PlatformUtil.OS.Linux; foreach (var test in new string[][] { new string [] { "C:\\path\\for\\linux", "/path/for/linux" }, new string [] { "c:\\path\\for\\linux", "/path/for/linux" }, new string [] { "D:\\path\\for\\linux", "/path/for/linux" }, new string [] { "C:\\", "/" }, new string [] { "/path/for/linux", "/path/for/linux" }, new string [] { "", "" }, new string [] { null, null }, }) { var winPath = test[0]; var linPath = test[1]; var got = info.TranslateContainerPathForImageOS(PlatformUtil.OS.Windows, winPath); Assert.True(string.Equals(got, linPath), $"Converted {winPath} expected {linPath}, got {got}"); } } }
public void DefaultContainerInfoMappings() { var dockerContainer = new Pipelines.ContainerResource() { Alias = "vsts_container_preview", Image = "foo" }; using (TestHostContext hc = CreateTestContext()) { ContainerInfo info = hc.CreateContainerInfo(dockerContainer, isJobContainer: false); Assert.True(info.TranslateToContainerPath(hc.GetDirectory(WellKnownDirectory.Tools)).EndsWith($"{Path.DirectorySeparatorChar}__t"), "Tools directory maps"); Assert.True(info.TranslateToContainerPath(hc.GetDirectory(WellKnownDirectory.Work)).EndsWith($"{Path.DirectorySeparatorChar}__w"), "Work directory maps"); Assert.True(info.TranslateToContainerPath(hc.GetDirectory(WellKnownDirectory.Root)).EndsWith($"{Path.DirectorySeparatorChar}__a"), "Root directory maps"); } }
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))); } }