public async Task PackagedScriptDoesNotExecute() { using (var tempPath = TemporaryDirectory.Create()) { foreach (var stage in defaultScriptStages) { File.WriteAllText(Path.Combine(tempPath.DirectoryPath, $"{stage}.ps1"), $"echo 'Hello from {stage}'"); } await CommandTestBuilder.CreateAsync <NoPackagedScriptCommand, MyProgram>() .WithArrange(context => { context.Variables.Add(KnownVariables.Package.RunPackageScripts, bool.TrueString); context.WithFilesToCopy(tempPath.DirectoryPath); }) .WithAssert(result => { result.WasSuccessful.Should().BeTrue(); foreach (var stage in defaultScriptStages) { result.FullLog.Should().NotContain($"Hello from {stage}"); } }) .Execute(true); } }
public void Deploy_Ensure_Tools_Are_Configured() { var packagePath = TestEnvironment.GetTestPath("Packages", "AzureResourceGroup"); var paramsFileContent = File.ReadAllText(Path.Combine(packagePath, "azure_website_params.json")); var parameters = JObject.Parse(paramsFileContent)["parameters"].ToString(); var psScript = @" $ErrorActionPreference = 'Continue' az --version Get-AzureEnvironment az group list"; CommandTestBuilder.CreateAsync <DeployAzureResourceGroupCommand, Program>() .WithArrange(context => { AddDefaults(context); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupDeploymentMode, "Complete"); context.Variables.Add("Octopus.Action.Azure.TemplateSource", "Inline"); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupTemplate, File.ReadAllText(Path.Combine(packagePath, "azure_website_template.json"))); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupTemplateParameters, parameters); context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.CustomScripts); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.Deploy, ScriptSyntax.PowerShell), psScript); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.PreDeploy, ScriptSyntax.CSharp), "Console.WriteLine(\"Hello from C#\");"); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.PostDeploy, ScriptSyntax.FSharp), "printfn \"Hello from F#\""); context.WithFilesToCopy(packagePath); }) .Execute(); }
public async Task CanDeployWebAppZip_ToDeploymentSlot() { var slotName = "stage"; greeting = "stage"; (string packagePath, string packageName, string packageVersion)packageinfo; var slotTask = webMgmtClient.WebApps.BeginCreateOrUpdateSlotAsync(resourceGroupName, resourceGroupName, site, slotName); var tempPath = TemporaryDirectory.Create(); new DirectoryInfo(tempPath.DirectoryPath).CreateSubdirectory("AzureZipDeployPackage"); File.WriteAllText(Path.Combine($"{tempPath.DirectoryPath}/AzureZipDeployPackage", "index.html"), "Hello #{Greeting}"); packageinfo.packagePath = $"{tempPath.DirectoryPath}/AzureZipDeployPackage.1.0.0.zip"; packageinfo.packageVersion = "1.0.0"; packageinfo.packageName = "AzureZipDeployPackage"; ZipFile.CreateFromDirectory($"{tempPath.DirectoryPath}/AzureZipDeployPackage", packageinfo.packagePath); await slotTask; await CommandTestBuilder.CreateAsync <DeployAzureAppServiceCommand, Program>().WithArrange(context => { context.WithPackage(packageinfo.packagePath, packageinfo.packageName, packageinfo.packageVersion); AddVariables(context); context.Variables.Add("Octopus.Action.Azure.DeploymentSlot", slotName); }).Execute(); await AssertContent($"{site.Name}-{slotName}.azurewebsites.net", $"Hello {greeting}"); }
public async Task CanDeployZip_ToLinuxFunctionApp_WithRunFromPackageFlag() { // Arrange var settings = await webMgmtClient.WebApps.ListApplicationSettingsAsync(resourceGroupName, site.Name); settings.Properties["WEBSITE_RUN_FROM_PACKAGE"] = "1"; await webMgmtClient.WebApps.UpdateApplicationSettingsAsync(resourceGroupName, site.Name, settings); var packageInfo = PrepareZipPackage(); // Act await CommandTestBuilder.CreateAsync <DeployAzureAppServiceCommand, Program>().WithArrange(context => { context.WithPackage(packageInfo.packagePath, packageInfo.packageName, packageInfo.packageVersion); AddVariables(context); }).Execute(); // Assert await DoWithRetries(10, async() => { await AssertContent($"{site.Name}.azurewebsites.net", rootPath: $"api/HttpExample?name={greeting}", actualText: $"Hello, {greeting}"); }, secondsBetweenRetries : 10); }
public async Task AssertConfigurationTransformsRuns() { using (var tempPath = TemporaryDirectory.Create()) { var expected = @"<configuration> <appSettings> <add key=""Environment"" value=""Test"" /> </appSettings> </configuration>".Replace("\r", String.Empty); var targetPath = Path.Combine(tempPath.DirectoryPath, "bar.config"); File.WriteAllText(targetPath, @"<configuration> <appSettings> <add key=""Environment"" value=""Dev"" /> </appSettings> </configuration>"); File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "bar.Release.config"), @"<configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform""> <appSettings> <add key=""Environment"" value=""Test"" xdt:Transform=""SetAttributes"" xdt:Locator=""Match(key)"" /> </appSettings> </configuration>"); await CommandTestBuilder.CreateAsync <MyCommand, MyProgram>() .WithArrange(context => { context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.ConfigurationTransforms); context.Variables.Add(KnownVariables.Package.AutomaticallyRunConfigurationTransformationFiles, bool.TrueString); context.WithFilesToCopy(tempPath.DirectoryPath); }) .WithAssert(result => { File.ReadAllText(targetPath).Replace("\r", String.Empty).Should().Be(expected); }) .Execute(); } }
public async Task WebAppIsFound_WithAndWithoutProxy() { IAzure azure = null; IResourceGroup resourceGroup = null; IWebApp webApp; try { (azure, resourceGroup, webApp) = await SetUpAzureWebApp(); azure.Should().NotBeNull(); resourceGroup.Should().NotBeNull(); webApp.Should().NotBeNull(); await CommandTestBuilder.CreateAsync <HealthCheckCommand, Program>() .WithArrange(context => SetUpVariables(context, resourceGroup.Name, webApp.Name)) .WithAssert(result => result.WasSuccessful.Should().BeTrue()) .Execute(); // Here we verify whether the proxy is correctly picked up // Since the proxy we use here is non-existent, health check to the same Web App should fail due this this proxy setting SetLocalEnvironmentProxySettings(NonExistentProxyHostname, NonExistentProxyPort); SetCiEnvironmentProxySettings(NonExistentProxyHostname, NonExistentProxyPort); await CommandTestBuilder.CreateAsync <HealthCheckCommand, Program>() .WithArrange(context => SetUpVariables(context, resourceGroup.Name, webApp.Name)) .WithAssert(result => result.WasSuccessful.Should().BeFalse()) .Execute(false); } finally { RestoreLocalEnvironmentProxySettings(); RestoreCiEnvironmentProxySettings(); await CleanResources(azure, resourceGroup); } }
public async Task CanDeployWarPackage() { // Need to spin up a specific app service with Tomcat installed // Need java installed on the test runner (MJH 2022-05-06: is this actually true? I don't see why we'd need java on the test runner) var javaSite = await webMgmtClient.WebApps.BeginCreateOrUpdateAsync(resourceGroupName, $"{resourceGroupName}-java", new Site(site.Location) { ServerFarmId = servicePlanId, SiteConfig = new SiteConfig { JavaVersion = "1.8", JavaContainer = "TOMCAT", JavaContainerVersion = "9.0" } }); (string packagePath, string packageName, string packageVersion)packageinfo; var assemblyFileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location); packageinfo.packagePath = Path.Combine(assemblyFileInfo.Directory.FullName, "sample.1.0.0.war"); packageinfo.packageVersion = "1.0.0"; packageinfo.packageName = "sample"; greeting = "java"; await CommandTestBuilder.CreateAsync <DeployAzureAppServiceCommand, Program>().WithArrange(context => { context.WithPackage(packageinfo.packagePath, packageinfo.packageName, packageinfo.packageVersion); AddVariables(context); context.Variables["Octopus.Action.Azure.WebAppName"] = javaSite.Name; context.Variables[PackageVariables.SubstituteInFilesTargets] = "test.jsp"; }).Execute(); await AssertContent($"{javaSite.Name}.azurewebsites.net", $"Hello! {greeting}", "test.jsp"); }
public async Task CalamariFlavourProgramAsync_PerformsReplacementCorrectlyWithoutCanonicalFileExtension(string configFileName, string variableName, string expectedReplacer) { const string newPort = "4444"; using (var tempPath = TemporaryDirectory.Create()) { var targetPath = Path.Combine(tempPath.DirectoryPath, configFileName); File.Copy(BuildConfigPath(configFileName), targetPath); await CommandTestBuilder.CreateAsync <NoOpPipelineCommand, AsyncFlavourProgram>() .WithArrange(context => { context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.StructuredConfigurationVariables); context.Variables.Add(ActionVariables.StructuredConfigurationVariablesTargets, configFileName); context.Variables.Add(variableName, newPort); context.WithFilesToCopy(tempPath.DirectoryPath); }) .WithAssert(result => { result.FullLog.Should().Contain($"Structured variable replacement succeeded on file {targetPath} with format {expectedReplacer}"); File.ReadAllText(targetPath).Should().Contain(newPort); }) .Execute(); } }
public async Task AssertStructuredConfigurationVariablesRuns() { using (var tempPath = TemporaryDirectory.Create()) { var expected = @"{ ""Environment"": ""Test"" }".Replace("\r", String.Empty); var targetPath = Path.Combine(tempPath.DirectoryPath, "myfile.json"); File.WriteAllText(targetPath, @"{ ""Environment"": ""Dev"" }"); await CommandTestBuilder.CreateAsync <MyCommand, MyProgram>() .WithArrange(context => { context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.StructuredConfigurationVariables); context.Variables.Add(ActionVariables.StructuredConfigurationVariablesTargets, "*.json"); context.Variables.Add("Environment", "Test"); context.WithFilesToCopy(tempPath.DirectoryPath); }) .WithAssert(result => { File.ReadAllText(targetPath).Replace("\r", String.Empty).Should().Be(expected); }) .Execute(); } }
public async Task AssertConfigurationVariablesRuns() { using (var tempPath = TemporaryDirectory.Create()) { var expected = @"<configuration> <appSettings> <add key=""Environment"" value=""Test"" /> </appSettings> </configuration>".Replace("\r", String.Empty); var targetPath = Path.Combine(tempPath.DirectoryPath, "Web.config"); File.WriteAllText(targetPath, @"<configuration> <appSettings> <add key=""Environment"" value=""Dev"" /> </appSettings> </configuration>"); await CommandTestBuilder.CreateAsync <MyCommand, MyProgram>() .WithArrange(context => { context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.ConfigurationTransforms + "," + KnownVariables.Features.ConfigurationVariables); context.Variables.Add(KnownVariables.Package.AutomaticallyUpdateAppSettingsAndConnectionStrings, "true"); context.Variables.Add("Environment", "Test"); context.WithFilesToCopy(tempPath.DirectoryPath); }) .WithAssert(result => { File.ReadAllText(targetPath).Replace("\r", String.Empty).Should().Be(expected); }) .Execute(); } }
public async Task Deploy_WebApp_To_A_Slot() { var webAppName = SdkContext.RandomResourceName(nameof(DeployAzureWebCommandFixture), 60); var slotName = "staging"; var webApp = await CreateWebApp(webAppName); var deploymentSlot = await webApp.DeploymentSlots.Define(slotName) .WithConfigurationFromParent() .WithAutoSwapSlotName("production") .CreateAsync(); using var tempPath = TemporaryDirectory.Create(); const string actualText = "Hello World"; File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "index.html"), actualText); await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { AddDefaults(context, webAppName); context.Variables.Add(SpecialVariables.Action.Azure.WebAppSlot, slotName); context.WithFilesToCopy(tempPath.DirectoryPath); }) .Execute(); await AssertContent(deploymentSlot.DefaultHostName, actualText); }
public async Task AssertPackageScriptsAreRun(bool deleteScripts) { using (var tempPath = TemporaryDirectory.Create()) { foreach (var stage in defaultScriptStages) { File.WriteAllText(Path.Combine(tempPath.DirectoryPath, $"{stage}.ps1"), $"echo 'Hello from {stage}'"); } await CommandTestBuilder.CreateAsync <MyCommand, MyProgram>() .WithArrange(context => { context.Variables.Add(KnownVariables.Package.RunPackageScripts, bool.TrueString); context.Variables.Add(KnownVariables.DeleteScriptsOnCleanup, deleteScripts.ToString()); context.WithFilesToCopy(tempPath.DirectoryPath); }) .WithAssert(result => { var currentIndex = 0; foreach (var stage in defaultScriptStages) { var index = result.FullLog.IndexOf($"Hello from {stage}", StringComparison.Ordinal); index.Should().BeGreaterThan(currentIndex); currentIndex = index; File.Exists(Path.Combine(tempPath.DirectoryPath, $"{stage}.ps1")).Should().Be(!deleteScripts); } }) .Execute(); } }
public async Task Deploy_WebApp_Preserve_App_Data() { var webAppName = SdkContext.RandomResourceName(nameof(DeployAzureWebCommandFixture), 60); var webApp = await CreateWebApp(webAppName); using var tempPath = TemporaryDirectory.Create(); Directory.CreateDirectory(Path.Combine(tempPath.DirectoryPath, "App_Data")); File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "App_Data", "newfile1.txt"), "Hello World"); File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "index.html"), "Hello World"); await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { AddDefaults(context, webAppName); context.Variables.Add(SpecialVariables.Action.Azure.RemoveAdditionalFiles, bool.TrueString); context.WithFilesToCopy(tempPath.DirectoryPath); }) .Execute(); var packagePath = TestEnvironment.GetTestPath("Packages", "AppDataList"); await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { AddDefaults(context, webAppName); context.Variables.Add(SpecialVariables.Action.Azure.RemoveAdditionalFiles, bool.TrueString); context.Variables.Add(SpecialVariables.Action.Azure.PreserveAppData, bool.TrueString); context.WithFilesToCopy(packagePath); }) .Execute(); await AssertContent(webApp.DefaultHostName, "newfile1.txt\r\nnewfile2.txt\r\n"); }
public async Task DeployToTwoTargetsInParallel_Succeeds() { // Arrange var packageInfo = PrepareFunctionAppZipPackage(); // Without larger changes to Calamari and the Test Framework, it's not possible to run two Calamari // processes in parallel in the same test method. Simulate the file locking behaviour by directly // opening the affected file instead var fileLock = File.Open(packageInfo.packagePath, FileMode.Open, FileAccess.Read, FileShare.Read); try { // Act var deployment = await CommandTestBuilder.CreateAsync <DeployAzureAppServiceCommand, Program>() .WithArrange(context => { context.WithPackage(packageInfo.packagePath, packageInfo.packageName, packageInfo.packageVersion); AddVariables(context); context.Variables[KnownVariables.Package.EnabledFeatures] = null; }).Execute(); // Assert deployment.Outcome.Should().Be(TestExecutionOutcome.Successful); } finally { fileLock.Close(); } }
public async Task WebAppIsNotFound() { var randomName = SdkContext.RandomResourceName(nameof(AzureWebAppHealthCheckActionHandlerFixtures), 60); await CommandTestBuilder.CreateAsync <HealthCheckCommand, Program>() .WithArrange(context => SetUpVariables(context, randomName, randomName)) .WithAssert(result => result.WasSuccessful.Should().BeFalse()) .Execute(false); }
public async Task CanDeployWebAppZip() { var packageInfo = PrepareZipPackage(); await CommandTestBuilder.CreateAsync <DeployAzureAppServiceCommand, Program>().WithArrange(context => { context.WithPackage(packageInfo.packagePath, packageInfo.packageName, packageInfo.packageVersion); AddVariables(context); }).Execute(); await AssertContent($"{site.Name}.azurewebsites.net", $"Hello {greeting}"); }
public Task AssertPipelineExtensionsAreExecuted() { return(CommandTestBuilder.CreateAsync <MyLoggingCommand, MyProgram>() .WithArrange(context => { context.Variables.Add(ActionVariables.Name, "Boo"); }) .WithAssert(result => { result.OutputVariables["ExecutionStages"].Value.Should().Be("IBeforePackageExtractionBehaviour;IAfterPackageExtractionBehaviour;IPreDeployBehaviour;IDeployBehaviour;IPostDeployBehaviour"); }) .Execute()); }
public async Task DeployingWithInvalidEnvironment_ThrowsAnException() { var packageinfo = PrepareZipPackage(); var commandResult = await CommandTestBuilder.CreateAsync <DeployAzureAppServiceCommand, Program>().WithArrange(context => { context.WithPackage(packageinfo.packagePath, packageinfo.packageName, packageinfo.packageVersion); AddVariables(context); context.AddVariable(AccountVariables.Environment, "NonSenseEnvironment"); }).Execute(false); commandResult.Outcome.Should().Be(TestExecutionOutcome.Unsuccessful); }
public Task ExecuteCommand() { // I can create content to be copied, this bypasses the extracting package using var tempPath = TemporaryDirectory.Create(); File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "PreDeploy.ps1"), "echo \"Hello from PreDeploy\""); return(CommandTestBuilder.CreateAsync <MyCommand, Program>() .WithArrange(context => { context.Variables.Add("MyVariable", "MyValue"); context.WithFilesToCopy(tempPath.DirectoryPath); }) .Execute()); }
public void Deploy_with_template_in_package() { var packagePath = TestEnvironment.GetTestPath("Packages", "AzureResourceGroup"); CommandTestBuilder.CreateAsync <DeployAzureResourceGroupCommand, Program>() .WithArrange(context => { AddDefaults(context); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupDeploymentMode, "Complete"); context.Variables.Add("Octopus.Action.Azure.TemplateSource", "Package"); context.Variables.Add("Octopus.Action.Azure.ResourceGroupTemplate", "azure_website_template.json"); context.Variables.Add("Octopus.Action.Azure.ResourceGroupTemplateParameters", "azure_website_params.json"); context.WithFilesToCopy(packagePath); }) .Execute(); }
public async Task Deploy_WebApp_Preserve_Files() { var webAppName = SdkContext.RandomResourceName(nameof(DeployAzureWebCommandFixture), 60); var webApp = await CreateWebApp(webAppName); using var tempPath = TemporaryDirectory.Create(); const string actualText = "Hello World"; Directory.CreateDirectory(Path.Combine(tempPath.DirectoryPath, "Keep")); Directory.CreateDirectory(Path.Combine(tempPath.DirectoryPath, "NotKeep")); File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "Keep", "index.html"), actualText); File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "NotKeep", "index.html"), actualText); await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { AddDefaults(context, webAppName); context.WithFilesToCopy(tempPath.DirectoryPath); }) .Execute(); using var tempPath2 = TemporaryDirectory.Create(); File.WriteAllText(Path.Combine(tempPath2.DirectoryPath, "newfile.html"), actualText); await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { AddDefaults(context, webAppName); context.Variables.Add(SpecialVariables.Action.Azure.RemoveAdditionalFiles, bool.TrueString); context.Variables.Add(SpecialVariables.Action.Azure.PreservePaths, "\\\\Keep;\\\\Keep\\\\index.html"); context.WithFilesToCopy(tempPath2.DirectoryPath); }) .Execute(); await AssertContent(webApp.DefaultHostName, actualText, "Keep"); await AssertContent(webApp.DefaultHostName, actualText, "newfile.html"); var response = await client.GetAsync($"https://{webApp.DefaultHostName}/NotKeep"); response.IsSuccessStatusCode.Should().BeFalse(); response.StatusCode.Should().Be(HttpStatusCode.NotFound); }
public Task EnsurePowerShellLanguageCodeGen() { using (var scriptFile = new TemporaryFile(Path.Combine(Path.GetTempPath(), Path.GetTempFileName()))) { var serializedRegistrations = JsonConvert.SerializeObject(new[] { new ScriptFunctionRegistration("MyFunc", String.Empty, "create-something", new Dictionary <string, FunctionParameter> { { "mystring", new FunctionParameter(ParameterType.String) }, { "myboolean", new FunctionParameter(ParameterType.Bool) }, { "mynumber", new FunctionParameter(ParameterType.Int) } }), new ScriptFunctionRegistration("MyFunc2", String.Empty, "create-something2", new Dictionary <string, FunctionParameter> { { "mystring", new FunctionParameter(ParameterType.String, "myboolean") }, { "myboolean", new FunctionParameter(ParameterType.Bool) }, { "mynumber", new FunctionParameter(ParameterType.Int, "myboolean") } }) }); return(CommandTestBuilder.CreateAsync <MyCommand, MyProgram>() .WithArrange(context => { context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.CustomScripts); var script = @"New-MyFunc -mystring 'Hello' -myboolean -mynumber 1 New-MyFunc2 -mystring 'Hello' -myboolean -mynumber 1 New-MyFunc2 -mystring 'Hello' -mynumber 1"; context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.Deploy, ScriptSyntax.PowerShell), script); context.Variables.Add(ScriptFunctionsVariables.Registration, serializedRegistrations); context.Variables.Add(ScriptFunctionsVariables.CopyScriptWrapper, scriptFile.FilePath); }) .WithAssert(result => { var script = File.ReadAllText(scriptFile.FilePath); this.Assent(script, TestEnvironment.AssentConfiguration); }) .Execute()); } }
public async Task CanDeployNugetPackage() { (string packagePath, string packageName, string packageVersion)packageinfo; greeting = "nuget"; var tempPath = TemporaryDirectory.Create(); new DirectoryInfo(tempPath.DirectoryPath).CreateSubdirectory("AzureZipDeployPackage"); var doc = new XDocument(new XElement("package", new XAttribute("xmlns", @"http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"), new XElement("metadata", new XElement("id", "AzureZipDeployPackage"), new XElement("version", "1.0.0"), new XElement("title", "AzureZipDeployPackage"), new XElement("authors", "Chris Thomas"), new XElement("description", "Test Package used to test nuget package deployments") ) )); await Task.Run(() => File.WriteAllText( Path.Combine($"{tempPath.DirectoryPath}/AzureZipDeployPackage", "index.html"), "Hello #{Greeting}")); using (var writer = new XmlTextWriter( Path.Combine($"{tempPath.DirectoryPath}/AzureZipDeployPackage", "AzureZipDeployPackage.nuspec"), Encoding.UTF8)) { doc.Save(writer); } packageinfo.packagePath = $"{tempPath.DirectoryPath}/AzureZipDeployPackage.1.0.0.nupkg"; packageinfo.packageVersion = "1.0.0"; packageinfo.packageName = "AzureZipDeployPackage"; ZipFile.CreateFromDirectory($"{tempPath.DirectoryPath}/AzureZipDeployPackage", packageinfo.packagePath); await CommandTestBuilder.CreateAsync <DeployAzureAppServiceCommand, Program>().WithArrange(context => { context.WithPackage(packageinfo.packagePath, packageinfo.packageName, packageinfo.packageVersion); AddVariables(context); }).Execute(); //await new AzureAppServiceBehaviour(new InMemoryLog()).Execute(runningContext); await AssertContent($"{site.Name}.azurewebsites.net", $"Hello {greeting}"); }
public async Task AssertStagedPackageIsExtracted() { using (var tempPath = TemporaryDirectory.Create()) { File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "Hello.html"), "Hello World!"); await CommandTestBuilder.CreateAsync <MyCommand, MyProgram>() .WithArrange(context => { context.WithNewNugetPackage(tempPath.DirectoryPath, "MyPackage", "1.0.0"); }) .WithAssert(result => { File.Exists(Path.Combine(tempPath.DirectoryPath, "Hello.html")).Should().BeTrue(); }) .Execute(); } }
public void Deploy_with_template_inline() { var packagePath = TestEnvironment.GetTestPath("Packages", "AzureResourceGroup"); var paramsFileContent = File.ReadAllText(Path.Combine(packagePath, "azure_website_params.json")); var parameters = JObject.Parse(paramsFileContent)["parameters"].ToString(); CommandTestBuilder.CreateAsync <DeployAzureResourceGroupCommand, Program>() .WithArrange(context => { AddDefaults(context); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupDeploymentMode, "Complete"); context.Variables.Add("Octopus.Action.Azure.TemplateSource", "Inline"); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupTemplate, File.ReadAllText(Path.Combine(packagePath, "azure_website_template.json"))); context.Variables.Add(SpecialVariables.Action.Azure.ResourceGroupTemplateParameters, parameters); context.WithFilesToCopy(packagePath); }) .Execute(); }
public async Task Deploy_WebApp_Using_AppOffline() { var webAppName = SdkContext.RandomResourceName(nameof(DeployAzureWebCommandFixture), 60); var webApp = await CreateWebApp(webAppName); using var tempPath = TemporaryDirectory.Create(); const string actualText = "I'm broken"; File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "index.html"), "Hello World"); File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "App_Offline.htm"), actualText); await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { AddDefaults(context, webAppName); context.WithFilesToCopy(tempPath.DirectoryPath); }) .Execute(); var packagePath = TestEnvironment.GetTestPath("Packages", "BrokenApp"); await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { AddDefaults(context, webAppName); context.Variables.Add(SpecialVariables.Action.Azure.AppOffline, bool.TrueString); context.WithFilesToCopy(packagePath); }) .Execute(); var response = await client.GetAsync($"https://{webApp.DefaultHostName}"); response.IsSuccessStatusCode.Should().BeFalse(); response.StatusCode.Should().Be(HttpStatusCode.ServiceUnavailable); var result = await response.Content.ReadAsStringAsync(); result.Should().Be(actualText); }
public async Task Deploy_WebApp_From_Package() { var webAppName = SdkContext.RandomResourceName(nameof(DeployAzureWebCommandFixture), 60); var webApp = await CreateWebApp(webAppName); using var tempPath = TemporaryDirectory.Create(); var actualText = "Hello World"; File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "index.html"), actualText); await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { AddDefaults(context, webAppName); context.WithNewNugetPackage(tempPath.DirectoryPath, "Hello", "1.0.0"); }) .Execute(); await AssertContent(webApp.DefaultHostName, actualText); }
public async Task CanDeployZip_ToLinuxFunctionApp() { // Arrange var packageInfo = PrepareZipPackage(); // Act await CommandTestBuilder.CreateAsync <DeployAzureAppServiceCommand, Program>().WithArrange(context => { context.WithPackage(packageInfo.packagePath, packageInfo.packageName, packageInfo.packageVersion); AddVariables(context); }).Execute(); // Assert await DoWithRetries(10, async() => { await AssertContent($"{site.Name}.azurewebsites.net", rootPath: $"api/HttpExample?name={greeting}", actualText: $"Hello, {greeting}"); }, secondsBetweenRetries : 10); }
public async Task AssertSubstituteInFilesRuns() { using (var tempPath = TemporaryDirectory.Create()) { var targetPath = Path.Combine(tempPath.DirectoryPath, "myconfig.json"); File.WriteAllText(targetPath, "{ foo: '#{Hello}' }"); string glob = "**/*config.json"; await CommandTestBuilder.CreateAsync <MyCommand, MyProgram>() .WithArrange(context => { context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.SubstituteInFiles); context.Variables.Add(PackageVariables.SubstituteInFilesTargets, glob); context.Variables.Add("Hello", "Hello World"); context.WithFilesToCopy(tempPath.DirectoryPath); }) .WithAssert(result => { File.ReadAllText(targetPath).Should().Be("{ foo: 'Hello World' }"); }) .Execute(); } }
public async Task Deploy_WebApp_Ensure_Tools_Are_Configured() { var webAppName = SdkContext.RandomResourceName(nameof(DeployAzureWebCommandFixture), 60); var webApp = await CreateWebApp(webAppName); using var tempPath = TemporaryDirectory.Create(); const string actualText = "Hello World"; File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "index.html"), actualText); var psScript = @" $ErrorActionPreference = 'Continue' az --version az group list"; File.WriteAllText(Path.Combine(tempPath.DirectoryPath, "PreDeploy.ps1"), psScript); // This should be references from Sashimi.Server.Contracts, since Calamari.AzureWebApp is a net461 project this cannot be included. var AccountType = "Octopus.Account.AccountType"; await CommandTestBuilder.CreateAsync <DeployAzureWebCommand, Program>() .WithArrange(context => { context.Variables.Add(AccountType, "AzureServicePrincipal"); AddDefaults(context, webAppName); context.Variables.Add(KnownVariables.Package.EnabledFeatures, KnownVariables.Features.CustomScripts); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.Deploy, ScriptSyntax.PowerShell), psScript); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.PreDeploy, ScriptSyntax.CSharp), "Console.WriteLine(\"Hello from C#\");"); context.Variables.Add(KnownVariables.Action.CustomScripts.GetCustomScriptStage(DeploymentStages.PostDeploy, ScriptSyntax.FSharp), "printfn \"Hello from F#\""); context.WithFilesToCopy(tempPath.DirectoryPath); }) .WithAssert(result => { result.FullLog.Should().Contain("Hello from C#"); result.FullLog.Should().Contain("Hello from F#"); }) .Execute(); await AssertContent(webApp.DefaultHostName, actualText); }