Exemple #1
0
            public async Task UploadDefinition_UploadsDefinition_IfObjectDoesntExist()
            {
                var logger         = Substitute.For <ILogger <PipelineDeployer> >();
                var fileFetcher    = Substitute.For <GithubFileFetcher>();
                var deployer       = Substitute.For <DeployStackFacade>();
                var statusNotifier = Substitute.For <GithubStatusNotifier>();
                var sumComputer    = Substitute.For <Sha256SumComputer>();
                var config         = Options.Create(new Config {
                    ArtifactStore = bucketName
                });
                var s3Client         = Substitute.For <IAmazonS3>();
                var pipelineDeployer = new PipelineDeployer(s3Client, sumComputer, fileFetcher, statusNotifier, deployer, config, logger);

                s3Client
                .When(client => client.GetObjectMetadataAsync(Any <string>(), Any <string>()))
                .Do(client => throw new Exception());


                sumComputer.ComputeSum(Any <string>()).Returns(sum);
                var result = await pipelineDeployer.UploadDefinition(githubRepo, definition);

                result.Should().BeEquivalentTo(expectedKey);
                await s3Client.Received().GetObjectMetadataAsync(Is(bucketName), Is(expectedKey));

                await s3Client.Received().PutObjectAsync(Is <PutObjectRequest>(req =>
                                                                               req.BucketName == bucketName &&
                                                                               req.Key == expectedKey &&
                                                                               req.ContentBody == definition
                                                                               ));
            }
Exemple #2
0
            public async Task Deploy_ShouldNotifySuccess_IfNoUpdatesPerformed()
            {
                var logger           = Substitute.For <ILogger <PipelineDeployer> >();
                var fileFetcher      = Substitute.For <GithubFileFetcher>();
                var deployer         = Substitute.For <DeployStackFacade>();
                var sumComputer      = Substitute.For <Sha256SumComputer>();
                var statusNotifier   = Substitute.For <GithubStatusNotifier>();
                var s3Client         = Substitute.For <IAmazonS3>();
                var pipelineDeployer = new PipelineDeployer(s3Client, sumComputer, fileFetcher, statusNotifier, deployer, config, logger);

                fileFetcher.Fetch(Any <string>(), Is(templateFileName), Any <string>()).Returns(template);
                fileFetcher.Fetch(Any <string>(), Is(definitionFileName), Any <string>()).Returns((string)null);

                deployer
                .When(x => x.Deploy(Any <DeployStackContext>()))
                .Do(x => throw new NoUpdatesException(""));

                await pipelineDeployer.Deploy(new PushEvent
                {
                    Ref        = gitRef,
                    Repository = new Repository
                    {
                        Name          = githubRepo,
                        ContentsUrl   = contentsUrl,
                        DefaultBranch = githubBranch
                    },
                    HeadCommit = new Commit {
                        Id = commitSha
                    }
                });

                await statusNotifier.Received().NotifySuccess(Is(githubRepo), Is(commitSha));
            }
Exemple #3
0
            public async Task Deploy_NotifyPending_IfTemplateWasFound()
            {
                var logger           = Substitute.For <ILogger <PipelineDeployer> >();
                var fileFetcher      = Substitute.For <GithubFileFetcher>();
                var deployer         = Substitute.For <DeployStackFacade>();
                var sumComputer      = Substitute.For <Sha256SumComputer>();
                var statusNotifier   = Substitute.For <GithubStatusNotifier>();
                var s3Client         = Substitute.For <IAmazonS3>();
                var pipelineDeployer = new PipelineDeployer(s3Client, sumComputer, fileFetcher, statusNotifier, deployer, config, logger);

                fileFetcher.Fetch(Any <string>(), Is(templateFileName), Any <string>()).Returns(template);
                fileFetcher.Fetch(Any <string>(), Is(definitionFileName), Any <string>()).Returns((string)null);

                await pipelineDeployer.Deploy(new PushEvent
                {
                    Ref        = gitRef,
                    Repository = new Repository
                    {
                        Name          = githubRepo,
                        ContentsUrl   = contentsUrl,
                        DefaultBranch = githubBranch
                    },
                    HeadCommit = new Commit {
                        Id = commitSha
                    }
                });

                await statusNotifier.Received().NotifyPending(Is(githubRepo), Is(commitSha));
            }
Exemple #4
0
            public async Task Deploy_ShouldNotDeployStack_IfTemplateWasNotFound()
            {
                var logger           = Substitute.For <ILogger <PipelineDeployer> >();
                var fileFetcher      = Substitute.For <GithubFileFetcher>();
                var deployer         = Substitute.For <DeployStackFacade>();
                var sumComputer      = Substitute.For <Sha256SumComputer>();
                var statusNotifier   = Substitute.For <GithubStatusNotifier>();
                var s3Client         = Substitute.For <IAmazonS3>();
                var pipelineDeployer = new PipelineDeployer(s3Client, sumComputer, fileFetcher, statusNotifier, deployer, config, logger);

                fileFetcher.Fetch(Any <string>(), Is(templateFileName), Any <string>()).Returns((string)null);

                await pipelineDeployer.Deploy(new PushEvent
                {
                    Ref        = gitRef,
                    Repository = new Repository
                    {
                        ContentsUrl = contentsUrl
                    },
                    HeadCommit = new Commit {
                        Id = commitSha
                    }
                });

                await deployer.DidNotReceiveWithAnyArgs().Deploy(null !);
            }
Exemple #5
0
            public async Task Deploy_ShouldDeployStackWithPipelineDefinition_IfPipelineDefinitionWasFound()
            {
                var logger           = Substitute.For <ILogger <PipelineDeployer> >();
                var fileFetcher      = Substitute.For <GithubFileFetcher>();
                var deployer         = Substitute.For <DeployStackFacade>();
                var sumComputer      = Substitute.For <Sha256SumComputer>();
                var statusNotifier   = Substitute.For <GithubStatusNotifier>();
                var s3Client         = Substitute.For <IAmazonS3>();
                var pipelineDeployer = new PipelineDeployer(s3Client, sumComputer, fileFetcher, statusNotifier, deployer, config, logger);

                fileFetcher.Fetch(Any <string>(), Is(templateFileName), Any <string>()).Returns(template);
                fileFetcher.Fetch(Any <string>(), Is(definitionFileName), Any <string>()).Returns(definition);
                sumComputer.ComputeSum(Any <string>()).Returns(sum);

                await pipelineDeployer.Deploy(new PushEvent
                {
                    Ref        = gitRef,
                    Repository = new Repository
                    {
                        Name          = githubRepo,
                        ContentsUrl   = contentsUrl,
                        DefaultBranch = githubBranch
                    },
                    HeadCommit = new Commit {
                        Id = commitSha
                    }
                });

                await deployer.Received().Deploy(Is <DeployStackContext>(req =>
                                                                         req.PassRoleArn == roleArn &&
                                                                         req.Template == template &&
                                                                         req.NotificationArn == notificationArn &&
                                                                         req.ClientRequestToken == commitSha &&
                                                                         req.StackName == $"{githubRepo}-{stackSuffix}" &&
                                                                         req.Parameters.Count() == 6 &&
                                                                         req.Parameters.Any(parameter => parameter.ParameterKey == "PipelineDefinitionBucket" && parameter.ParameterValue == bucketName) &&
                                                                         req.Parameters.Any(parameter => parameter.ParameterKey == "PipelineDefinitionKey" && parameter.ParameterValue == expectedKey) &&
                                                                         req.Parameters.Any(parameter => parameter.ParameterKey == "GithubToken" && parameter.ParameterValue == githubToken) &&
                                                                         req.Parameters.Any(parameter => parameter.ParameterKey == "GithubOwner" && parameter.ParameterValue == githubOwner) &&
                                                                         req.Parameters.Any(parameter => parameter.ParameterKey == "GithubRepo" && parameter.ParameterValue == githubRepo) &&
                                                                         req.Parameters.Any(parameter => parameter.ParameterKey == "GithubBranch" && parameter.ParameterValue == githubBranch)
                                                                         ));
            }
Exemple #6
0
            public async Task UploadDefinition_DoesNotUploadDefinition_IfAlreadyExists()
            {
                var logger         = Substitute.For <ILogger <PipelineDeployer> >();
                var fileFetcher    = Substitute.For <GithubFileFetcher>();
                var deployer       = Substitute.For <DeployStackFacade>();
                var s3Client       = Substitute.For <IAmazonS3>();
                var sumComputer    = Substitute.For <Sha256SumComputer>();
                var statusNotifier = Substitute.For <GithubStatusNotifier>();
                var config         = Options.Create(new Config {
                    ArtifactStore = bucketName
                });
                var pipelineDeployer = new PipelineDeployer(s3Client, sumComputer, fileFetcher, statusNotifier, deployer, config, logger);

                sumComputer.ComputeSum(Any <string>()).Returns(sum);
                var result = await pipelineDeployer.UploadDefinition(githubRepo, definition);

                result.Should().BeEquivalentTo(expectedKey);
                await s3Client.Received().GetObjectMetadataAsync(Is(bucketName), Is(expectedKey));

                await s3Client.DidNotReceiveWithAnyArgs().PutObjectAsync(null !);
            }
Exemple #7
0
            public async Task Deploy_FetchesPipelineDefinition()
            {
                var logger           = Substitute.For <ILogger <PipelineDeployer> >();
                var fileFetcher      = Substitute.For <GithubFileFetcher>();
                var deployer         = Substitute.For <DeployStackFacade>();
                var statusNotifier   = Substitute.For <GithubStatusNotifier>();
                var sumComputer      = Substitute.For <Sha256SumComputer>();
                var s3Client         = Substitute.For <IAmazonS3>();
                var pipelineDeployer = new PipelineDeployer(s3Client, sumComputer, fileFetcher, statusNotifier, deployer, config, logger);

                await pipelineDeployer.Deploy(new PushEvent
                {
                    Ref        = gitRef,
                    Repository = new Repository
                    {
                        ContentsUrl = contentsUrl
                    },
                    HeadCommit = new Commit {
                        Id = commitSha
                    }
                });

                await fileFetcher.Received().Fetch(Is(contentsUrl), Is(definitionFileName), Is(gitRef));
            }