Update integrsation test implementation

This commit is contained in:
Chris Cheetham 2020-08-17 11:33:18 -04:00
Родитель 1a90e0be85
Коммит 049260c218
1 изменённых файлов: 49 добавлений и 128 удалений

Просмотреть файл

@ -19,7 +19,6 @@ using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Steeltoe.Initializr.TemplateEngine.Models;
using Steeltoe.Initializr.TemplateEngine.Services;
@ -33,163 +32,65 @@ namespace Steeltoe.Initializr.TemplateEngine.Test.IntegrationTests
public class IntegrationTests : XunitLoggingBase
{
private readonly ITestOutputHelper _testOutputHelper;
private readonly LoggerFactory _xUnitLoggerFactory;
private readonly LoggerFactory _loggerFactory;
public IntegrationTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
_testOutputHelper = testOutputHelper;
_xUnitLoggerFactory = new LoggerFactory();
_xUnitLoggerFactory.AddProvider(new XunitLoggerProvider(testOutputHelper));
_loggerFactory = new LoggerFactory();
}
public static IEnumerable<object[]> GetAllCombinations(Type templateServiceType, string templateName, DotnetFramework version, int take)
[Fact]
public void Scratch()
{
ITemplateService templateService;
if (templateServiceType == typeof(MustacheTemplateService))
var argsList = GetArgs(typeof(MustacheTemplateService), DotnetFramework.NetCoreApp31, "Steeltoe-WebApi");
foreach (var args in argsList)
{
templateService = new MustacheTemplateService(
TestHelper.GetConfiguration(),
new LoggerFactory().CreateLogger<MustacheTemplateService>());
_testOutputHelper.WriteLine($"dotnet {args[1]}, template {args[2]}, dependency {args[3]}");
}
else
{
throw new ArgumentOutOfRangeException(nameof(templateServiceType));
}
var dependencies = templateService.GetDependencies(version, templateName);
return from deps in GetCombinations(dependencies.Select(d => d.ShortName), take)
select new object[] { templateService, templateName, version, string.Join(",", deps) };
}
[Theory]
[MemberData(nameof(GetAllCombinations), typeof(MustacheTemplateService), "Steeltoe-WebApi", DotnetFramework.NetCoreApp21, 1, DisableDiscoveryEnumeration = true)]
public async Task CreateTemplate_Mustache_WebApi_V2_OneAtaTime_Test(ITemplateService templateService, string templateName, string framework, string depString)
[MemberData(nameof(GetArgs), typeof(MustacheTemplateService), DotnetFramework.NetCoreApp21, "Steeltoe-WebApi")]
public async Task Steeltoe24Dotnet21(ITemplateService service, DotnetFramework dotNet, string template, string dependency)
{
_testOutputHelper.WriteLine(depString);
await CreateTemplate_Test(templateService, templateName, framework, depString);
await GenerateAndBuildProject(service, dotNet, template, dependency);
}
[Theory]
[MemberData(nameof(GetAllCombinations), typeof(MustacheTemplateService), "Steeltoe-WebApi", DotnetFramework.NetCoreApp21, int.MaxValue, DisableDiscoveryEnumeration = true)]
public async Task CreateTemplate_Mustache_WebApi_V2_All_Test(ITemplateService templateService, string templateName, string framework, string depString)
[MemberData(nameof(GetArgs), typeof(MustacheTemplateService), DotnetFramework.NetCoreApp31, "Steeltoe-WebApi")]
public async Task Steeltoe24Dotnet31(ITemplateService service, DotnetFramework dotNet,
string template, string dependency)
{
_testOutputHelper.WriteLine(depString);
await CreateTemplate_Test(templateService, templateName, framework, depString);
await GenerateAndBuildProject(service, dotNet, template, dependency);
}
// [Theory]
// [MemberData(nameof(GetAllCombinations), typeof(TemplateService), "Steeltoe-WebApi", TemplateVersion.V2, 1, DisableDiscoveryEnumeration = true)]
// public async Task CreateTemplate_Dotnet_WebApi_V2_OneAtaTime_Test(ITemplateService templateService, string templateName, TemplateVersion version, string depString)
// {
// _testOutputHelper.WriteLine(depString);
// await CreateTemplate_Test(templateService, templateName, version, depString);
// }
// [Theory]
// [MemberData(nameof(GetAllCombinations), typeof(TemplateService), "Steeltoe-WebApi", TemplateVersion.V2, int.MaxValue, DisableDiscoveryEnumeration = true)]
// public async Task CreateTemplate_Dotnet_WebApi_V2_All_Test(ITemplateService templateService, string templateName, TemplateVersion version, string depString)
// {
// _testOutputHelper.WriteLine(depString);
// await CreateTemplate_Test(templateService, templateName, version, depString);
// }
private static IEnumerable<List<string>> GetCombinations(IEnumerable<string> deps, int take)
{
var returnValue = new List<List<string>>();
var depArray = deps as string[] ?? deps.ToArray();
var length = depArray.Length;
var combinations = Math.Pow(2, length);
for (var i = 0; i < combinations; i++)
{
var combinationDeps = new List<string>();
for (var bit = 0; bit <= length; bit++)
{
// right shift by _bit_ bits and check if set
if (((i >> bit) & 1) == 1)
{
combinationDeps.Add(depArray[bit]);
}
}
if (combinationDeps.Count == take || (take == int.MaxValue && combinationDeps.Count == depArray.Length))
{
returnValue.Add(combinationDeps);
}
}
return returnValue;
}
/*
[Theory]
[InlineData("Actuators")]
[InlineData("CircuitBreaker")]
[InlineData("CloudFoundry")]
[InlineData("Discovery")]
[InlineData("DynamicLogger")]
[InlineData("MongoDB")]
[InlineData("MySql")]
[InlineData("MySqlEFCore")]
[InlineData("OAuthConnector")]
[InlineData("Postgres")]
[InlineData("PostgresEFCore")]
[InlineData("RabbitMQ")]
[InlineData("Redis")]
[InlineData("SQLServer")]
[InlineData("ConfigServer")]
[InlineData("PlaceholderConfig")]
[InlineData("RandomValueConfig")]
[InlineData("Dockerfile")]
public async Task TestBuildSteeltoe2(string dependency)
[MemberData(nameof(GetArgs), typeof(MustacheTemplateService), DotnetFramework.NetCoreApp31, "Steeltoe-WebApi")]
public async Task Steeltoe30Dotnet31(ITemplateService service, DotnetFramework dotNet,
string template, string dependency)
{
var templateService = new MustacheTemplateService(new NullLogger<MustacheTemplateService>());
await CreateTemplate_Test(templateService, "Steeltoe-WebApi", DotnetTemplateVersion.V2, dependency);
await GenerateAndBuildProject(service, dotNet, template, dependency);
}
*/
/*
[Theory]
[InlineData("Actuators")]
[InlineData("CircuitBreaker")]
[InlineData("AzureSpringCloud")]
[InlineData("CloudFoundry")]
[InlineData("Discovery")]
[InlineData("DynamicLogger")]
[InlineData("MongoDB")]
[InlineData("MySql")]
[InlineData("MySqlEFCore")]
[InlineData("OAuthConnector")]
[InlineData("Postgres")]
[InlineData("PostgresEFCore")]
[InlineData("RabbitMQ")]
[InlineData("Redis")]
[InlineData("SQLServer")]
[InlineData("ConfigServer")]
[InlineData("PlaceholderConfig")]
[InlineData("RandomValueConfig")]
[InlineData("Dockerfile")]
public async Task TestBuildSteeltoe3(string dependency)
// TODO: test Steeltoe 3
// TODO: test uber projects
private async Task GenerateAndBuildProject(
ITemplateService service,
DotnetFramework dotNet,
string template,
string dependency,
string steeltoe = "2.4.4")
{
var templateService = new MustacheTemplateService(new NullLogger<MustacheTemplateService>());
await CreateTemplate_Test(templateService, "Steeltoe-WebApi", DotnetTemplateVersion.V3, dependency, "3.0.0-rc1");
}
*/
private async Task CreateTemplate_Test(ITemplateService service, string template, string framework, string dependency, string steeltoe = "2.4.4")
{
_testOutputHelper.WriteLine($"testing Steeltoe {steeltoe} with {dependency}");
_testOutputHelper.WriteLine(
$"Generating and Building: Steeltoe {steeltoe}, DotNet {dotNet}, Template {template}, dependency {dependency}");
var archive = await service.GenerateProjectArchiveAsync(new GeneratorModel()
{
Dependencies = dependency,
Template = template,
ProjectName = "Foo.Bar",
TargetFramework = framework,
TargetFramework = dotNet == DotnetFramework.NetCoreApp21 ? "netcoreapp2.1" : "netcoreapp3.1",
SteeltoeVersion = steeltoe,
});
@ -212,5 +113,25 @@ namespace Steeltoe.Initializr.TemplateEngine.Test.IntegrationTests
output.Contains("Build succeeded."),
$"Error compiling {dependency}. \n {output}");
}
public static IEnumerable<object[]> GetArgs(Type templateServiceType, DotnetFramework dotNet, string template)
{
var service = BuildTemplateService(templateServiceType);
var deps = service.GetDependencies(dotNet, template).Select(dep => dep.ShortName.ToLower());
return from dep in deps select new object[] {service, dotNet, template, dep};
}
static ITemplateService BuildTemplateService(Type type)
{
if (type == typeof(MustacheTemplateService))
{
return new MustacheTemplateService(
TestHelper.GetConfiguration(),
new LoggerFactory().CreateLogger<MustacheTemplateService>());
}
return null;
}
}
}