public async Task SaveChanges_SmallTemplate_SubmitsDirectly() { // arrange var alarm = Alarm(); var group = Group(); var stackName = ExpectedStackName(group); SetupListStacksToReturnStackNames(); SetupStackStatusSequence(stackName, new List <string> { "CREATE_COMPLETE" }); var s3Location = new S3Location("bucket", "s3/path"); var deployer = MakeDeployer(s3Location, TimeSpan.Zero, TimeSpan.FromMinutes(1)); var sut = new CloudFormationAlarmCreator(deployer, new ConsoleAlarmLogger(false)); // act sut.AddAlarms(group, new[] { alarm }); await sut.SaveChanges(false); // assert _s3Mock .Verify(x => x.PutObjectAsync( It.IsAny <PutObjectRequest>(), It.IsAny <CancellationToken>()), Times.Never); _cloudFormationMock .Verify(x => x.CreateStackAsync( It.Is <CreateStackRequest>(s => s.StackName == stackName && s.TemplateURL == null && !string.IsNullOrWhiteSpace(s.TemplateBody)), It.IsAny <CancellationToken>()), Times.Exactly(1)); }
public CloudformationStackDeployer( IAlarmLogger logger, IAmazonCloudFormation cloudformation, IAmazonS3 s3Client, S3Location s3Location) : this(logger, cloudformation, s3Client, s3Location, TimeSpan.FromSeconds(2), TimeSpan.FromMinutes(5)) { }
private CloudFormationStackDeployer MakeDeployer( S3Location s3Location, TimeSpan wait, TimeSpan waitTimeout) { return(new CloudFormationStackDeployer( new ConsoleAlarmLogger(false), _cloudFormationMock.Object, _s3Mock.Object, s3Location, wait, waitTimeout)); }
public async Task SaveChanges_LargeTemplate_SubmitsViaS3() { // arrange var alarms = Enumerable.Range(0, 120) .Select(x => Alarm($"alarm-{x}")) .ToList(); var stackName = ExpectedStackName(alarms.First().AlertingGroup); SetupListStacksToReturnStackNames(); SetupStackStatusSequence(stackName, new List <string> { "CREATE_COMPLETE" }); var s3Location = new S3Location("bucket", "s3/path"); var sut = new CloudFormationAlarmCreator( new CloudformationStackDeployer( new ConsoleAlarmLogger(false), _cloudFormationMock.Object, _s3Mock.Object, s3Location, TimeSpan.Zero, TimeSpan.FromMinutes(1) )); foreach (var alarm in alarms) { sut.AddAlarm(alarm); } // act await sut.SaveChanges(false); // assert var s3Path = $"{s3Location.Path}/{stackName}.json"; _s3Mock .Verify(x => x.PutObjectAsync( It.Is <PutObjectRequest>(r => r.BucketName == s3Location.BucketName && r.Key == s3Path), It.IsAny <CancellationToken>())); var expectedStackUrl = $"https://s3.amazonaws.com/{s3Location.BucketName}/{s3Path}"; _cloudFormationMock .Verify(x => x.CreateStackAsync( It.Is <CreateStackRequest>(s => s.StackName == stackName && s.TemplateURL == expectedStackUrl && s.TemplateBody == null), It.IsAny <CancellationToken>()), Times.Exactly(1)); }
public CloudformationStackDeployer( IAlarmLogger logger, IAmazonCloudFormation cloudformation, IAmazonS3 s3Client, S3Location s3Location, TimeSpan wait, TimeSpan timeout) { _logger = logger; _cloudformation = cloudformation; _stackStatusCheckTimeout = timeout; _stackStatusCheckInterval = wait; _s3Client = s3Client; _s3Location = s3Location; }
public async Task SaveChanges_ConfigResultsInMultipleStacks_Aborts() { //arrange var alarm1 = Alarm("alarm 1"); var alarm2 = Alarm("alarm 2"); // two groups with the same name but different suffix, so that the equality/hash compares will fail // but would result in two cloudformation stacks with the same name var group1 = Group("name", "suffix1"); var group2 = Group("name", "suffix2"); SetupListStacksToReturnStackNames(); SetupStackStatusSequence(ExpectedStackName(group1), new List <string> { "CREATE_COMPLETE", "CREATE_COMPLETE" }); var s3Location = new S3Location("bucket", "s3/path"); var deployer = MakeDeployer(s3Location, TimeSpan.Zero, TimeSpan.FromMinutes(1)); var sut = new CloudFormationAlarmCreator(deployer, new ConsoleAlarmLogger(false)); //act Exception caught = null; try { sut.AddAlarms(group1, new[] { alarm1 }); sut.AddAlarms(group2, new[] { alarm2 }); await sut.SaveChanges(false);; } catch (Exception ex) { caught = ex; } //assert Assert.That(caught, Is.Not.Null); Assert.That(caught.Message, Contains.Substring("Cannot deploy: multiple stacks would be created with the same name")); }