Exemplo n.º 1
0
        public async Task Generate_HealthChecks()
        {
            var applicationName = "health-checks";
            var environment     = "production";
            var projectName     = "health-all";

            await DockerAssert.DeleteDockerImagesAsync(output, projectName);

            using var projectDirectory = TestHelpers.CopyTestProjectDirectory(applicationName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye-all.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content = await File.ReadAllTextAsync(Path.Combine(projectDirectory.DirectoryPath, $"{applicationName}-generate-{environment}.yaml"));

                var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{applicationName}.yaml");

                YamlAssert.Equals(expectedContent, content, output);

                await DockerAssert.AssertImageExistsAsync(output, projectName);
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, projectName);
            }
        }
Exemplo n.º 2
0
        public async Task SingleProjectGenerateTest()
        {
            await DockerAssert.DeleteDockerImagesAsync(output, "test/test-project");

            var projectName = "single-project";
            var environment = "production";

            using var projectDirectory = CopyTestProjectDirectory(projectName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            // Need to add docker registry for generate
            application.Registry = new ContainerRegistry("test");

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content = await File.ReadAllTextAsync(Path.Combine(projectDirectory.DirectoryPath, $"{projectName}-generate-{environment}.yaml"));

                var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{projectName}.yaml");

                YamlAssert.Equals(expectedContent, content, output);

                await DockerAssert.AssertImageExistsAsync(output, "test/test-project");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "test/test-project");
            }
        }
Exemplo n.º 3
0
        public void Init_ProjectKinds()
        {
            using var projectDirectory = CopyTestProjectDirectory("project-types");

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "project-types.sln"));

            var(content, _) = InitHost.CreateTyeFileContent(projectFile, force: false);

            var expectedContent = File.ReadAllText("testassets/init/project-types.yaml");

            YamlAssert.Equals(expectedContent, content);
        }
Exemplo n.º 4
0
        public void Console_Normalization_Service_Name()
        {
            using var projectDirectory = CopyTestProjectDirectory("Console.Normalization.svc.Name");

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "Console.Normalization.svc.Name.csproj"));

            var(content, _) = InitHost.CreateTyeFileContent(projectFile, force: false);

            var expectedContent = File.ReadAllText("testassets/init/console-normalization-svc-name.yaml");

            YamlAssert.Equals(expectedContent, content);
        }
Exemplo n.º 5
0
        public void Init_WorksForMultipleProjects()
        {
            using var projectDirectory = CopyTestProjectDirectory("multi-project");
            File.Delete(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "multi-project.sln"));

            var(content, _) = InitHost.CreateTyeFileContent(projectFile, force: false);

            var expectedContent = File.ReadAllText("testassets/init/multi-project.yaml");

            YamlAssert.Equals(expectedContent, content);
        }
Exemplo n.º 6
0
        public void Init_WorksForMultipleProjects_FileComparison()
        {
            using var projectDirectory = CopyTestProjectDirectory("frontend-backend");

            // delete already present yaml
            File.Delete(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "frontend-backend.sln"));

            var(content, _) = InitHost.CreateTyeFileContent(projectFile, force: false);
            var expectedContent = File.ReadAllText("testassets/init/frontend-backend.yaml");

            output.WriteLine(content);

            YamlAssert.Equals(expectedContent, content);
        }
Exemplo n.º 7
0
        public async Task Generate_Ingress()
        {
            var applicationName = "apps-with-ingress";
            var environment     = "production";

            await DockerAssert.DeleteDockerImagesAsync(output, "appa");

            await DockerAssert.DeleteDockerImagesAsync(output, "appa");

            using var projectDirectory = TestHelpers.CopyTestProjectDirectory(applicationName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content = await File.ReadAllTextAsync(Path.Combine(projectDirectory.DirectoryPath, $"{applicationName}-generate-{environment}.yaml"));

                if (await KubectlDetector.GetKubernetesServerVersion(outputContext) >= new Version(1, 19))
                {
                    var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{applicationName}.1.19.yaml");

                    YamlAssert.Equals(expectedContent, content, output);
                }
                else
                {
                    var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{applicationName}.1.18.yaml");

                    YamlAssert.Equals(expectedContent, content, output);
                }

                await DockerAssert.AssertImageExistsAsync(output, "appa");

                await DockerAssert.AssertImageExistsAsync(output, "appb");
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, "appa");

                await DockerAssert.DeleteDockerImagesAsync(output, "appb");
            }
        }
Exemplo n.º 8
0
        public async Task Generate_DirectDependencyForEnvVars()
        {
            var applicationName = "multirepo";
            var projectName     = "results";
            var otherProject    = "worker";
            var environment     = "production";

            await DockerAssert.DeleteDockerImagesAsync(output, projectName);

            await DockerAssert.DeleteDockerImagesAsync(output, otherProject);

            using var projectDirectory = TestHelpers.CopyTestProjectDirectory(applicationName);

            var projectFile = new FileInfo(Path.Combine(projectDirectory.DirectoryPath, "results", "tye.yaml"));

            var outputContext = new OutputContext(sink, Verbosity.Debug);
            var application   = await ApplicationFactory.CreateAsync(outputContext, projectFile);

            try
            {
                await GenerateHost.ExecuteGenerateAsync(outputContext, application, environment, interactive : false);

                // name of application is the folder
                var content = await File.ReadAllTextAsync(Path.Combine(projectDirectory.DirectoryPath, "results", $"VotingSample-generate-{environment}.yaml"));

                var expectedContent = await File.ReadAllTextAsync($"testassets/generate/{applicationName}.yaml");

                YamlAssert.Equals(expectedContent, content, output);
                await DockerAssert.AssertImageExistsAsync(output, projectName);

                await DockerAssert.AssertImageExistsAsync(output, otherProject);
            }
            finally
            {
                await DockerAssert.DeleteDockerImagesAsync(output, projectName);

                await DockerAssert.DeleteDockerImagesAsync(output, otherProject);
            }
        }