Stop using IISExpress .config templates (#142)

This commit is contained in:
Pavel Krymets 2018-08-16 12:08:58 -07:00 committed by GitHub
parent 89506dfcf0
commit 30b01d2460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 1062 deletions

View File

@ -38,10 +38,14 @@ namespace ServerComparison.FunctionalTests
var deploymentParameters = new DeploymentParameters(variant) var deploymentParameters = new DeploymentParameters(variant)
{ {
ApplicationPath = Helpers.GetApplicationPath(), ApplicationPath = Helpers.GetApplicationPath()
ServerConfigTemplateContent = Helpers.GetNginxConfigContent(variant.Server, "nginx.conf"),
}; };
if (variant.Server == ServerType.Nginx)
{
deploymentParameters.ServerConfigTemplateContent = Helpers.GetNginxConfigContent("nginx.conf");
}
using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{ {
var deploymentResult = await deployer.DeployAsync(); var deploymentResult = await deployer.DeployAsync();

View File

@ -29,33 +29,10 @@ namespace ServerComparison.FunctionalTests
throw new Exception($"Solution root could not be found using {applicationBasePath}"); throw new Exception($"Solution root could not be found using {applicationBasePath}");
} }
public static string GetConfigContent(ServerType serverType, string iisConfig, string nginxConfig) public static string GetNginxConfigContent(string nginxConfig)
{ {
var applicationBasePath = AppContext.BaseDirectory; var applicationBasePath = AppContext.BaseDirectory;
var content = File.ReadAllText(Path.Combine(applicationBasePath, nginxConfig));
string content = null;
if (serverType == ServerType.IISExpress)
{
content = File.ReadAllText(Path.Combine(applicationBasePath, iisConfig));
}
else if (serverType == ServerType.Nginx)
{
content = File.ReadAllText(Path.Combine(applicationBasePath, nginxConfig));
}
return content;
}
public static string GetNginxConfigContent(ServerType serverType, string nginxConfig)
{
var applicationBasePath = AppContext.BaseDirectory;
string content = null;
if (serverType == ServerType.Nginx)
{
content = File.ReadAllText(Path.Combine(applicationBasePath, nginxConfig));
}
return content; return content;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,9 @@ using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Server.IntegrationTesting; using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Server.IntegrationTesting.IIS;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Testing; using Microsoft.Extensions.Logging.Testing;
@ -81,9 +83,9 @@ namespace ServerComparison.FunctionalTests
return ResponseCompression(variant, CheckAppCompressionAsync, hostCompression: true); return ResponseCompression(variant, CheckAppCompressionAsync, hostCompression: true);
} }
private async Task ResponseCompression(TestVariant variant, private async Task ResponseCompression(TestVariant variant,
Func<HttpClient, ILogger, Task> scenario, Func<HttpClient, ILogger, Task> scenario,
bool hostCompression, bool hostCompression,
[CallerMemberName] string testName = null) [CallerMemberName] string testName = null)
{ {
testName = $"{testName}_{variant.Server}_{variant.Tfm}_{variant.Architecture}_{variant.ApplicationType}"; testName = $"{testName}_{variant.Server}_{variant.Tfm}_{variant.Architecture}_{variant.ApplicationType}";
@ -96,13 +98,37 @@ namespace ServerComparison.FunctionalTests
ApplicationPath = Helpers.GetApplicationPath(), ApplicationPath = Helpers.GetApplicationPath(),
EnvironmentName = "ResponseCompression", EnvironmentName = "ResponseCompression",
}; };
if (hostCompression)
if (variant.Server == ServerType.Nginx)
{ {
deploymentParameters.ServerConfigTemplateContent = Helpers.GetNginxConfigContent(variant.Server, "nginx.conf"); deploymentParameters.ServerConfigTemplateContent = hostCompression
? Helpers.GetNginxConfigContent("nginx.conf")
: Helpers.GetNginxConfigContent("NoCompression.conf");
} }
else else if (variant.Server == ServerType.IISExpress && !hostCompression)
{ {
deploymentParameters.ServerConfigTemplateContent = Helpers.GetConfigContent(variant.Server, "NoCompression.config", "NoCompression.conf"); var iisDeploymentParameters = new IISDeploymentParameters(deploymentParameters);
iisDeploymentParameters.ServerConfigActionList.Add(
(element, _) => {
var compressionElement = element
.RequiredElement("system.webServer")
.RequiredElement("httpCompression");
compressionElement
.RequiredElement("dynamicTypes")
.Elements()
.SkipLast(1)
.Remove();
compressionElement
.RequiredElement("staticTypes")
.Elements()
.SkipLast(1)
.Remove();
// last element in both dynamicTypes and staticTypes disables compression
// <add mimeType="*/*" enabled="false" />
});
deploymentParameters = iisDeploymentParameters;
} }
using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))

View File

@ -87,10 +87,14 @@ namespace ServerComparison.FunctionalTests
var deploymentParameters = new DeploymentParameters(variant) var deploymentParameters = new DeploymentParameters(variant)
{ {
ApplicationPath = Helpers.GetApplicationPath(), ApplicationPath = Helpers.GetApplicationPath(),
EnvironmentName = "Responses", EnvironmentName = "Responses"
ServerConfigTemplateContent = Helpers.GetNginxConfigContent(variant.Server, "nginx.conf"),
}; };
if (variant.Server == ServerType.Nginx)
{
deploymentParameters.ServerConfigTemplateContent = Helpers.GetNginxConfigContent("nginx.conf");
}
using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory)) using (var deployer = IISApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
{ {
var deploymentResult = await deployer.DeployAsync(); var deploymentResult = await deployer.DeployAsync();