From b53a6f9a25da561a1dc402c6e152460e0edd09b6 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 29 Aug 2017 08:40:12 -0700 Subject: [PATCH] Install site extension on top of existing dotnet (#97) --- build/repo.targets | 11 +++- ...NetCore.AzureAppServices.TestBundle.csproj | 1 + .../install.cmd | 14 +++++ .../AzureFixture.cs | 4 +- .../Directory.Build.props.template | 2 + ...re.AzureAppServices.FunctionalTests.csproj | 1 + .../README.md | 12 ++++ .../TemplateFunctionalTests.cs | 62 ++++--------------- .../Templates/BasicAppServices.json | 32 ---------- 9 files changed, 54 insertions(+), 85 deletions(-) create mode 100644 src/Microsoft.AspNetCore.AzureAppServices.TestBundle/install.cmd create mode 100644 test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Directory.Build.props.template create mode 100644 test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/README.md delete mode 100644 test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Templates/BasicAppServices.json diff --git a/build/repo.targets b/build/repo.targets index 1f5b31648a..85ba1a8fe5 100644 --- a/build/repo.targets +++ b/build/repo.targets @@ -10,12 +10,17 @@ - - + - + + + + + + + build\dotnet.version diff --git a/src/Microsoft.AspNetCore.AzureAppServices.TestBundle/Microsoft.AspNetCore.AzureAppServices.TestBundle.csproj b/src/Microsoft.AspNetCore.AzureAppServices.TestBundle/Microsoft.AspNetCore.AzureAppServices.TestBundle.csproj index e8576c1e8d..8dfc194aea 100644 --- a/src/Microsoft.AspNetCore.AzureAppServices.TestBundle/Microsoft.AspNetCore.AzureAppServices.TestBundle.csproj +++ b/src/Microsoft.AspNetCore.AzureAppServices.TestBundle/Microsoft.AspNetCore.AzureAppServices.TestBundle.csproj @@ -21,6 +21,7 @@ + diff --git a/src/Microsoft.AspNetCore.AzureAppServices.TestBundle/install.cmd b/src/Microsoft.AspNetCore.AzureAppServices.TestBundle/install.cmd new file mode 100644 index 0000000000..ee3f1ff9cf --- /dev/null +++ b/src/Microsoft.AspNetCore.AzureAppServices.TestBundle/install.cmd @@ -0,0 +1,14 @@ +SET DOTNET=D:\Program Files (x86)\dotnet +SET RUNTIMES=%DOTNET%\shared\Microsoft.NETCore.App +robocopy "%DOTNET%" "." /E /XC /XN /XO /NFL /NDL ^ + /XD "%DOTNET%\sdk" ^ + /XD "%RUNTIMES%\1.0.3" ^ + /XD "%RUNTIMES%\1.0.4" ^ + /XD "%RUNTIMES%\1.1.0" ^ + /XD "%RUNTIMES%\1.1.0-preview1-001100-00" ^ + /XD "%RUNTIMES%\1.1.1" ^ + /XD "%RUNTIMES%\2.0.0-preview1-002111-00" ^ + /XD "%RUNTIMES%\2.0.0-preview2-25407-01" + +if %errorlevel% geq 8 exit /b 1 +exit /b 0 \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/AzureFixture.cs b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/AzureFixture.cs index a3026813c4..007ebd8daf 100644 --- a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/AzureFixture.cs +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/AzureFixture.cs @@ -18,6 +18,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Testing; using Microsoft.Rest; using Newtonsoft.Json.Linq; +using OperatingSystem = Microsoft.Azure.Management.AppService.Fluent.OperatingSystem; namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests { @@ -64,7 +65,8 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests Plan = Azure.AppServices.AppServicePlans.Define(servicePlanName) .WithRegion(Region.USWest2) .WithExistingResourceGroup(ResourceGroup) - .WithFreePricingTier() + .WithPricingTier(PricingTier.BasicB1) + .WithOperatingSystem(OperatingSystem.Windows) .Create(); } diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Directory.Build.props.template b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Directory.Build.props.template new file mode 100644 index 0000000000..8c119d5413 --- /dev/null +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Directory.Build.props.template @@ -0,0 +1,2 @@ + + diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj index e8cab4ef79..0da59f8f4e 100644 --- a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Microsoft.AspNetCore.AzureAppServices.FunctionalTests.csproj @@ -9,6 +9,7 @@ + diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/README.md b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/README.md new file mode 100644 index 0000000000..4be4a604af --- /dev/null +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/README.md @@ -0,0 +1,12 @@ +Running functional tests locally: + +1. Set following environment variables: + -. `SiteExtensionFeed` - feed where site extension is published + -. `APIKEY` - Nuget API key for extension publish feed + -. `AZURE_AUTH_CLIENT_ID` - Azure service principal client id + -. `AZURE_AUTH_CLIENT_SECRET` - Azure service principal client secret + -. `AZURE_AUTH_TENANT` - Azure service principal tenant + -. See https://github.com/Azure/azure-sdk-for-net/blob/Fluent/AUTH.md on how to create service principal + +2. Run `.\build /t:BuildSiteExtension /t:PushSiteExtension` to build and push site extension +2. Run `.\build /t:Test /p:AntaresTests=true` to run tests using the site extension \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs index 679886103c..3aff1126e0 100644 --- a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs +++ b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/TemplateFunctionalTests.cs @@ -34,49 +34,15 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests } [Theory] - [InlineData("web", "Hello World!")] - [InlineData("razor", "Learn how to build ASP.NET apps that can run anywhere.")] - [InlineData("mvc", "Learn how to build ASP.NET apps that can run anywhere.")] - public async Task DotnetNewWebRunsInWebApp(string template, string expected) + [InlineData("2.0", "web", "Hello World!")] + [InlineData("2.0", "razor", "Learn how to build ASP.NET apps that can run anywhere.")] + [InlineData("2.0", "mvc", "Learn how to build ASP.NET apps that can run anywhere.")] + [InlineData("latest", "web", "Hello World!")] + [InlineData("latest", "razor", "Learn how to build ASP.NET apps that can run anywhere.")] + [InlineData("latest", "mvc", "Learn how to build ASP.NET apps that can run anywhere.")] + public async Task DotnetNewWebRunsWebAppOnLatestRuntime(string dotnetVersion, string template, string expected) { - var testId = nameof(DotnetNewWebRunsInWebApp) + template; - - using (var logger = GetLogger(testId)) - { - var site = await _fixture.Deploy("Templates\\BasicAppServices.json", baseName: testId); - var testDirectory = GetTestDirectory(testId); - var dotnet = DotNet(logger, testDirectory, "2.0"); - - await dotnet.ExecuteAndAssertAsync("new " + template); - - InjectMiddlware(testDirectory, RuntimeInformationMiddlewareType, RuntimeInformationMiddlewareFile); - - await site.BuildPublishProfileAsync(testDirectory.FullName); - - await dotnet.ExecuteAndAssertAsync("publish /p:PublishProfile=Profile"); - - using (var httpClient = site.CreateClient()) - { - var getResult = await httpClient.GetAsync("/"); - getResult.EnsureSuccessStatusCode(); - Assert.Contains(expected, await getResult.Content.ReadAsStringAsync()); - - getResult = await httpClient.GetAsync("/runtimeInfo"); - getResult.EnsureSuccessStatusCode(); - - var runtimeInfo = JsonConvert.DeserializeObject(await getResult.Content.ReadAsStringAsync()); - ValidateRuntimeInfo(runtimeInfo, dotnet.Command); - } - } - } - - [Theory] - [InlineData("web", "Hello World!")] - [InlineData("razor", "Learn how to build ASP.NET apps that can run anywhere.")] - [InlineData("mvc", "Learn how to build ASP.NET apps that can run anywhere.")] - public async Task DotnetNewWebRunsWebAppOnLatestRuntime(string template, string expected) - { - var testId = nameof(DotnetNewWebRunsWebAppOnLatestRuntime) + template; + var testId = nameof(DotnetNewWebRunsWebAppOnLatestRuntime) + template + dotnetVersion.Replace('.', '_'); using (var logger = GetLogger(testId)) { @@ -90,7 +56,7 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests }); var testDirectory = GetTestDirectory(testId); - var dotnet = DotNet(logger, testDirectory, "latest"); + var dotnet = DotNet(logger, testDirectory, dotnetVersion); await dotnet.ExecuteAndAssertAsync("new " + template); @@ -98,8 +64,6 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests FixAspNetCoreVersion(testDirectory, dotnet.Command); - await dotnet.ExecuteAndAssertAsync("restore"); - await site.BuildPublishProfileAsync(testDirectory.FullName); await dotnet.ExecuteAndAssertAsync("publish /p:PublishProfile=Profile"); @@ -198,21 +162,21 @@ namespace Microsoft.AspNetCore.AzureAppServices.FunctionalTests return new TestLogger(factory, factory.CreateLogger(callerName)); } - private TestCommand DotNet(TestLogger logger, DirectoryInfo workingDirectory, string sufix) + private TestCommand DotNet(TestLogger logger, DirectoryInfo workingDirectory, string suffix) { - return new TestCommand(GetDotNetPath(sufix)) + return new TestCommand(GetDotNetPath(suffix)) { Logger = logger, WorkingDirectory = workingDirectory.FullName }; } - private static string GetDotNetPath(string sufix) + private static string GetDotNetPath(string suffix) { var current = new DirectoryInfo(Directory.GetCurrentDirectory()); while (current != null) { - var dotnetSubdir = new DirectoryInfo(Path.Combine(current.FullName, ".test-dotnet", sufix)); + var dotnetSubdir = new DirectoryInfo(Path.Combine(current.FullName, ".test-dotnet", suffix)); if (dotnetSubdir.Exists) { var dotnetName = Path.Combine(dotnetSubdir.FullName, "dotnet.exe"); diff --git a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Templates/BasicAppServices.json b/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Templates/BasicAppServices.json deleted file mode 100644 index 6eefe37051..0000000000 --- a/test/Microsoft.AspNetCore.AzureAppServices.FunctionalTests/Templates/BasicAppServices.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "siteName": { - "type": "string" - }, - "hostingPlanName": { - "type": "string" - }, - "resourceGroupName": { - "type": "string" - } - }, - "resources": [ - { - "apiVersion": "2015-08-01", - "name": "[parameters('siteName')]", - "type": "Microsoft.Web/sites", - "location": "West US 2", - "properties": { - "serverFarmId": "[resourceId(parameters('resourceGroupName'), 'Microsoft.Web/serverFarms', parameters('hostingPlanName'))]" - } - } - ], - "outputs": { - "siteId": { - "type": "string", - "value": "[resourceId(parameters('resourceGroupName'), 'Microsoft.Web/sites', parameters('siteName'))]" - } - } -} \ No newline at end of file