public async Task Execute_MultipleWebAppSlotsWithTags_WebAppWithTags_CreatesCorrectTargets() { // Arrange var variables = new CalamariVariables(); var context = new RunningDeployment(variables); CreateVariables(context); var log = new InMemoryLog(); var sut = new TargetDiscoveryBehaviour(log); // Set expected tags on each slot of the web app AND the web app itself var tags = new Dictionary <string, string> { { TargetTags.EnvironmentTagName, EnvironmentName }, { TargetTags.RoleTagName, Role }, }; await CreateOrUpdateTestWebApp(tags); await CreateOrUpdateTestWebAppSlots(tags); // Act await sut.Execute(context); var serviceMessageToCreateWebAppTarget = TargetDiscoveryHelpers.CreateWebAppTargetCreationServiceMessage(resourceGroupName, appName, AccountId, Role, null); log.StandardOut.Should().Contain(serviceMessageToCreateWebAppTarget.ToString(), "A target should be created for the web app itself as well as for the slots"); // Assert foreach (var slotName in slotNames) { var serviceMessageToCreateTargetForSlot = TargetDiscoveryHelpers.CreateWebAppDeploymentSlotTargetCreationServiceMessage(resourceGroupName, appName, slotName, AccountId, Role, null); log.StandardOut.Should().Contain(serviceMessageToCreateTargetForSlot.ToString()); } }
public async Task Execute_WebAppWithNonMatchingTags_CreatesNoTargets() { // Arrange var variables = new CalamariVariables(); var context = new RunningDeployment(variables); this.CreateVariables(context); var log = new InMemoryLog(); var sut = new TargetDiscoveryBehaviour(log); // Set expected tags on our web app var tags = new Dictionary <string, string> { { TargetTags.EnvironmentTagName, EnvironmentName }, { TargetTags.RoleTagName, "a-different-role" }, }; await CreateOrUpdateTestWebApp(tags); // Act await sut.Execute(context); // Assert var serviceMessageToCreateWebAppTarget = TargetDiscoveryHelpers.CreateWebAppTargetCreationServiceMessage(resourceGroupName, appName, AccountId, Role, null); log.StandardOut.Should().NotContain(serviceMessageToCreateWebAppTarget.ToString(), "The web app target should not be created as the role tag did not match"); }
public async Task Execute_LogsError_WhenContextIsMissing() { // Arrange var variables = new CalamariVariables(); var context = new RunningDeployment(variables); var log = new InMemoryLog(); var sut = new TargetDiscoveryBehaviour(log); // Act await sut.Execute(context); // Assert log.StandardOut.Should().Contain(line => line.Contains("Could not find target discovery context in variable")); log.StandardOut.Should().Contain(line => line.Contains("Aborting target discovery.")); }
public async Task Exectute_LogsError_WhenContextIsInIncorrectFormat() { // Arrange var variables = new CalamariVariables(); var context = new RunningDeployment(variables); context.Variables.Add("Octopus.TargetDiscovery.Context", "bogus json"); var log = new InMemoryLog(); var sut = new TargetDiscoveryBehaviour(log); // Act await sut.Execute(context); // Assert log.StandardOut.Should().Contain(line => line.Contains("Target discovery context from variable Octopus.TargetDiscovery.Context is in wrong format")); log.StandardOut.Should().Contain(line => line.Contains("Aborting target discovery.")); }
public async Task Execute_MultipleWebAppSlotsWithPartialTags_WebAppWithPartialTags_CreatesNoTargets() { // Arrange var variables = new CalamariVariables(); var context = new RunningDeployment(variables); CreateVariables(context); var log = new InMemoryLog(); var sut = new TargetDiscoveryBehaviour(log); // Set partial tags on each slot of the web app AND the remaining ones on the web app itself var webAppTags = new Dictionary <string, string> { { TargetTags.EnvironmentTagName, EnvironmentName }, }; var slotTags = new Dictionary <string, string> { { TargetTags.RoleTagName, Role }, }; await CreateOrUpdateTestWebApp(webAppTags); await CreateOrUpdateTestWebAppSlots(slotTags); // Act await sut.Execute(context); var serviceMessageToCreateWebAppTarget = TargetDiscoveryHelpers.CreateWebAppTargetCreationServiceMessage(resourceGroupName, appName, AccountId, Role, null); log.StandardOut.Should().NotContain(serviceMessageToCreateWebAppTarget.ToString(), "A target should not be created for the web app as the tags directly on the web app do not match, even though when combined with the slot tags they do"); // Assert foreach (var slotName in slotNames) { var serviceMessageToCreateTargetForSlot = TargetDiscoveryHelpers.CreateWebAppDeploymentSlotTargetCreationServiceMessage(resourceGroupName, appName, slotName, AccountId, Role, null); log.StandardOut.Should().NotContain(serviceMessageToCreateTargetForSlot.ToString(), "A target should not be created for the web app slot as the tags directly on the slot do not match, even though when combined with the web app tags they do"); } }