コード例 #1
0
        public static void Validate(
            IEnumerable <EnvironmentVariableInfo> variables,
            string imageType,
            ImageDescriptor imageDescriptor,
            ImageTestHelper imageTestHelper)
        {
            const char           delimiter = '|';
            IEnumerable <string> echoParts;
            string invokeCommand;
            char   delimiterEscape;

            if (DockerHelper.IsLinuxContainerModeEnabled)
            {
                echoParts       = variables.Select(envVar => $"${envVar.Name}");
                invokeCommand   = $"/bin/sh -c";
                delimiterEscape = '\\';
            }
            else
            {
                echoParts       = variables.Select(envVar => $"%{envVar.Name}%");
                invokeCommand   = $"CMD /S /C";
                delimiterEscape = '^';
            }

            string appId = $"envvar-{DateTime.Now.ToFileTime()}";

            string combinedValues = imageTestHelper.DockerHelper.Run(
                image: imageTestHelper.GetImage(imageType, imageDescriptor.Version, imageDescriptor.OsVariant),
                name: appId,
                command: $"{invokeCommand} \"echo {String.Join($"{delimiterEscape}{delimiter}", echoParts)}\"");

            string[] values = combinedValues.Split(delimiter);
            Assert.Equal(variables.Count(), values.Count());

            for (int i = 0; i < values.Count(); i++)
            {
                EnvironmentVariableInfo variable = variables.ElementAt(i);

                string actualValue;
                // Process unset variables in Windows
                if (!DockerHelper.IsLinuxContainerModeEnabled &&
                    string.Equals(values[i], $"%{variable.Name}%", StringComparison.Ordinal))
                {
                    actualValue = string.Empty;
                }
                else
                {
                    actualValue = values[i];
                }

                if (variable.AllowAnyValue)
                {
                    Assert.NotEmpty(actualValue);
                }
                else
                {
                    Assert.Equal(variable.ExpectedValue, actualValue);
                }
            }
        }
コード例 #2
0
        public void VerifyEnvironmentVariables(ImageDescriptor imageDescriptor)
        {
            List <EnvironmentVariableInfo> variables = new List <EnvironmentVariableInfo>();

            variables.AddRange(RuntimeOnlyImageTests.GetRuntimeEnvironmentVariableInfos(imageDescriptor));

            variables.Add(new EnvironmentVariableInfo("ROSLYN_COMPILER_LOCATION",
                                                      @"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Roslyn"));

            if (imageDescriptor.OsVariant != OsVersion.WSC_LTSC2016 &&
                imageDescriptor.OsVariant != OsVersion.WSC_LTSC2019 &&
                imageDescriptor.OsVariant != OsVersion.WSC_1903)
            {
                variables.Add(new EnvironmentVariableInfo("DOTNET_USE_POLLING_FILE_WATCHER", "true"));
            }

            EnvironmentVariableInfo.Validate(variables, "sdk", imageDescriptor, imageTestHelper);
        }
コード例 #3
0
        protected void VerifyCommonEnvironmentVariables(IEnumerable <EnvironmentVariableInfo> variables, ImageDescriptor imageDescriptor)
        {
            const char           delimiter = '|';
            string               appId     = $"envvar-{DateTime.Now.ToFileTime()}";
            IEnumerable <string> echoParts = variables.Select(envVar => $"%{envVar.Name}%");

            string combinedValues = ImageTestHelper.DockerHelper.Run(
                image: ImageTestHelper.GetImage(ImageType, imageDescriptor.Version, imageDescriptor.OsVariant),
                name: appId,
                entrypointOverride: "cmd",
                command: $"CMD /S /C \"echo {String.Join($"^{delimiter}", echoParts)}\"");

            string[] values = combinedValues.Split(delimiter);
            Assert.Equal(variables.Count(), values.Count());

            for (int i = 0; i < values.Count(); i++)
            {
                EnvironmentVariableInfo variable = variables.ElementAt(i);

                string actualValue;
                // Process unset variables in Windows
                if (!DockerHelper.IsLinuxContainerModeEnabled &&
                    string.Equals(values[i], $"%{variable.Name}%", StringComparison.Ordinal))
                {
                    actualValue = string.Empty;
                }
                else
                {
                    actualValue = values[i];
                }

                if (variable.AllowAnyValue)
                {
                    Assert.NotEmpty(actualValue);
                }
                else
                {
                    Assert.Equal(variable.ExpectedValue, actualValue);
                }
            }
        }
コード例 #4
0
 public void VerifyEnvironmentVariables(ImageDescriptor imageDescriptor)
 {
     EnvironmentVariableInfo.Validate(
         GetRuntimeEnvironmentVariableInfos(imageDescriptor), "runtime", imageDescriptor, imageTestHelper);
 }