Exemplo n.º 1
0
        public async Task ShouldSendTaskSuccessWithSupersededTrueIfNewerCommitExists(
            string token,
            Request request,
            [Substitute] SQSEvent sqsEvent,
            [Frozen, Substitute] IAmazonStepFunctions stepFunctionsClient,
            [Frozen, Options] IOptions <Config> options,
            [Frozen, Substitute] RequestFactory requestFactory,
            [Frozen, Substitute] S3GetObjectFacade s3GetObjectFacade,
            [Target] Handler handler
            )
        {
            request.Token           = token;
            request.CommitTimestamp = DateTime.Now - TimeSpan.FromHours(1);
            requestFactory.CreateFromSqsEvent(Any <SQSEvent>()).Returns(request);
            s3GetObjectFacade.TryGetObject <StateInfo>(null, null).ReturnsForAnyArgs(new StateInfo
            {
                LastCommitTimestamp = DateTime.Now
            });

            await handler.Handle(sqsEvent);

            var expectedOutput = Serialize(new
            {
                Superseded = true
            });

            await stepFunctionsClient.Received().SendTaskSuccessAsync(Is <SendTaskSuccessRequest>(req =>
                                                                                                  req.TaskToken == token &&
                                                                                                  req.Output == expectedOutput
                                                                                                  ));
        }
Exemplo n.º 2
0
 public Handler(
     IAwsFactory <IAmazonS3> s3Factory,
     GithubStatusNotifier githubStatusNotifier,
     S3GetObjectFacade s3GetObjectFacade,
     ILogger <Handler> logger
     )
 {
     this.s3Factory            = s3Factory;
     this.githubStatusNotifier = githubStatusNotifier;
     this.s3GetObjectFacade    = s3GetObjectFacade;
     this.logger = logger;
 }
Exemplo n.º 3
0
 public ApprovalCanceler(
     IAmazonS3 s3Client,
     IAmazonStepFunctions stepFunctionsClient,
     S3GetObjectFacade s3GetObjectFacade,
     IOptions <Config> config,
     ILogger <ApprovalCanceler> logger
     )
 {
     this.s3Client            = s3Client;
     this.stepFunctionsClient = stepFunctionsClient;
     this.s3GetObjectFacade   = s3GetObjectFacade;
     this.config = config.Value;
     this.logger = logger;
 }
Exemplo n.º 4
0
 public Handler(
     RequestFactory requestFactory,
     S3GetObjectFacade s3GetObjectFacade,
     IAmazonStepFunctions stepFunctionsClient,
     IAmazonS3 s3Client,
     IOptions <Config> options,
     ILogger <Handler> logger
     )
 {
     this.requestFactory      = requestFactory;
     this.s3GetObjectFacade   = s3GetObjectFacade;
     this.stepFunctionsClient = stepFunctionsClient;
     this.s3Client            = s3Client;
     this.config = options.Value;
     this.logger = logger;
 }
Exemplo n.º 5
0
        public async Task ShouldRetrieveStateFile(
            string bucket,
            string pipeline,
            Request request,
            [Substitute] SQSEvent sqsEvent,
            [Frozen, Options] IOptions <Config> options,
            [Frozen, Substitute] RequestFactory requestFactory,
            [Frozen, Substitute] S3GetObjectFacade s3GetObjectFacade,
            [Target] Handler handler
            )
        {
            options.Value.StateStore = bucket;
            request.Pipeline         = pipeline;
            requestFactory.CreateFromSqsEvent(Arg.Any <SQSEvent>()).Returns(request);

            await handler.Handle(sqsEvent);

            await s3GetObjectFacade.Received().TryGetObject <StateInfo>(Is(bucket), Is($"{pipeline}/state.json"));
        }
Exemplo n.º 6
0
        public async Task ShouldPutUpdatedStateInfoIfNewerCommitDoesntExist(
            string bucket,
            string pipeline,
            string token,
            Request request,
            [Substitute] SQSEvent sqsEvent,
            [Frozen, Substitute] IAmazonS3 s3Client,
            [Frozen, Options] IOptions <Config> options,
            [Frozen, Substitute] RequestFactory requestFactory,
            [Frozen, Substitute] S3GetObjectFacade s3GetObjectFacade,
            [Target] Handler handler
            )
        {
            options.Value.StateStore = bucket;
            request.Pipeline         = pipeline;
            request.Token            = token;
            request.CommitTimestamp  = DateTime.Now - TimeSpan.FromHours(1);

            requestFactory.CreateFromSqsEvent(Any <SQSEvent>()).Returns(request);
            s3GetObjectFacade.TryGetObject <StateInfo>(Arg.Any <string>(), Arg.Any <string>()).Returns(new StateInfo
            {
                LastCommitTimestamp = DateTime.Now - TimeSpan.FromHours(2)
            });

            await handler.Handle(sqsEvent);

            var expectedBody = Serialize(new StateInfo
            {
                LastCommitTimestamp = request.CommitTimestamp
            });

            await s3Client.Received().PutObjectAsync(Arg.Is <PutObjectRequest>(req =>
                                                                               req.BucketName == bucket &&
                                                                               req.Key == $"{pipeline}/state.json" &&
                                                                               req.ContentBody == expectedBody
                                                                               ));
        }
Exemplo n.º 7
0
 public Handler(IAmazonS3 s3Client, S3GetObjectFacade getObject)
 {
     this.s3Client  = s3Client;
     this.getObject = getObject;
 }
Exemplo n.º 8
0
 public Handler(
     S3GetObjectFacade s3GetObjectFacade
     )
 {
     this.s3GetObjectFacade = s3GetObjectFacade;
 }