public async Task GenerateDockerfilesCommand_MissingTemplate()
        {
            using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();
            GenerateDockerfilesCommand command = InitializeCommand(tempFolderContext, null, allowOptionalTemplates: false);

            await Assert.ThrowsAsync <InvalidOperationException>(command.ExecuteAsync);
        }
Exemplo n.º 2
0
        public async Task GenerateDockerfilesCommand_Validate_UpToDate()
        {
            using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();
            GenerateDockerfilesCommand command = InitializeCommand(tempFolderContext, dockerfile: ExpectedDockerfile, validate: true);

            await command.ExecuteAsync();

            _environmentServiceMock.Verify(o => o.Exit(It.IsAny <int>()), Times.Never);
        }
Exemplo n.º 3
0
        public async Task GenerateDockerfilesCommand_Canonical()
        {
            using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();
            GenerateDockerfilesCommand command = InitializeCommand(tempFolderContext);

            await command.ExecuteAsync();

            string generatedDockerfile = File.ReadAllText(Path.Combine(tempFolderContext.Path, DockerfilePath));

            Assert.Equal(ExpectedDockerfile.NormalizeLineEndings(generatedDockerfile), generatedDockerfile);
        }
Exemplo n.º 4
0
        public async Task GenerateDockerfilesCommand_Validate_OutOfSync()
        {
            using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();
            GenerateDockerfilesCommand command = InitializeCommand(tempFolderContext, validate: true);

            Exception actualException = await Assert.ThrowsAsync <Exception>(command.ExecuteAsync);

            Assert.Same(_exitException, actualException);
            _environmentServiceMock.Verify(o => o.Exit(It.IsAny <int>()), Times.Once);
            // Validate Dockerfile remains unmodified
            Assert.Equal(DefaultDockerfile, File.ReadAllText(Path.Combine(tempFolderContext.Path, DockerfilePath)));
        }
Exemplo n.º 5
0
        public async Task GenerateDockerfilesCommand_InvalidTemplate()
        {
            string template = "FROM $REPO:2.1-{{if:}}";

            using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();
            GenerateDockerfilesCommand command = InitializeCommand(tempFolderContext, template);

            Exception actualException = await Assert.ThrowsAsync <Exception>(command.ExecuteAsync);

            Assert.Same(_exitException, actualException);
            _environmentServiceMock.Verify(o => o.Exit(It.IsAny <int>()), Times.Once);
        }
Exemplo n.º 6
0
        private GenerateDockerfilesCommand InitializeCommand(
            TempFolderContext tempFolderContext,
            string dockerfileTemplate = DefaultDockerfileTemplate,
            string dockerfile         = DefaultDockerfile,
            bool validate             = false)
        {
            DockerfileHelper.CreateFile(DockerfileTemplatePath, tempFolderContext, dockerfileTemplate);
            DockerfileHelper.CreateFile(DockerfilePath, tempFolderContext, dockerfile);

            Manifest manifest = CreateManifest(
                CreateRepo("repo1",
                           CreateImage(
                               CreatePlatform(
                                   DockerfilePath,
                                   new string[] { "tag1" },
                                   OS.Linux,
                                   "buster-slim",
                                   Architecture.ARM,
                                   "v7",
                                   dockerfileTemplatePath: DockerfileTemplatePath),
                               CreatePlatform(
                                   DockerfilePath,
                                   new string[] { "tag2" },
                                   OS.Windows,
                                   "nanoserver-1903"),
                               CreatePlatform(
                                   DockerfilePath,
                                   new string[] { "tag3" },
                                   OS.Linux,
                                   "alpine3.12")))
                );

            AddVariable(manifest, "Variable1", "Value1");

            string manifestPath = Path.Combine(tempFolderContext.Path, "manifest.json");

            File.WriteAllText(manifestPath, JsonConvert.SerializeObject(manifest));

            _environmentServiceMock = new Mock <IEnvironmentService>();
            _environmentServiceMock
            .Setup(o => o.Exit(1))
            .Throws(_exitException);

            GenerateDockerfilesCommand command = new GenerateDockerfilesCommand(_environmentServiceMock.Object);

            command.Options.Manifest = manifestPath;
            command.Options.Validate = validate;
            command.LoadManifest();

            return(command);
        }
Exemplo n.º 7
0
        public void GenerateDockerfilesCommand_SupportedSymbols(string tag, string symbol, string expectedValue, bool isVariable = false)
        {
            using TempFolderContext tempFolderContext = TestHelper.UseTempFolder();
            GenerateDockerfilesCommand command = InitializeCommand(tempFolderContext);

            IReadOnlyDictionary <Value, Value> symbols = command.GetSymbols(command.Manifest.GetPlatformByTag(tag));

            Value variableValue;

            if (isVariable)
            {
                variableValue = symbols["VARIABLES"].Fields[symbol];
            }
            else
            {
                variableValue = symbols[symbol];
            }

            Assert.Equal(expectedValue, variableValue);
        }