Skip to content

Commit

Permalink
fix tests for linux/macos
Browse files Browse the repository at this point in the history
  • Loading branch information
simongdavies committed Jul 26, 2021
1 parent c6bda4a commit 488e009
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
19 changes: 11 additions & 8 deletions source/wagi.test/EndpointRouteBuilderExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class EndpointRouteBuilderExtensionsTest
public async Task Test_Handles_No_Configuration_As_Log_Warning()
{
var mockLogger = new Mock<ILogger>();

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsNoConfig.json", mockLoggerFactory);
Expand All @@ -36,7 +35,6 @@ public async Task Test_Handles_No_Configuration_As_Log_Warning()
public async Task Test_Handles_Configuration_With_Empty_Config()
{
var mockLogger = new Mock<ILogger>();

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsEmptyConfig.json", mockLoggerFactory);
Expand All @@ -49,7 +47,6 @@ public async Task Test_Handles_Configuration_With_Empty_Config()
public async Task Test_Handles_Configuration_With_WAT_Module()
{
var mockLogger = new Mock<ILogger>();

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsWATConfig.json", mockLoggerFactory);
Expand All @@ -62,7 +59,6 @@ public async Task Test_Handles_Configuration_With_WAT_Module()
public async Task Test_Handles_Configuration_With_WAGI_Module()
{
var mockLogger = new Mock<ILogger>();

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsWAGIConfig.json", mockLoggerFactory);
Expand All @@ -75,18 +71,26 @@ public async Task Test_Handles_Configuration_With_WAGI_Module()
public void Test_Module_Is_Missing()
{
var mockLogger = new Mock<ILogger>();
var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsModuleIsMissingConfig.json", mockLoggerFactory, context => new StartupTest(context.Configuration, typeof(OptionsValidationException), $"Module file testdata/modules{Path.DirectorySeparatorChar}dontexist.wasm not found for module name dontexist{Environment.NewLine}"));
testServer.CreateClient();
}

[Fact]
public void Test_Route_Is_Missing()
{
var mockLogger = new Mock<ILogger>();
var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsModuleIsMissingConfig.json", mockLoggerFactory, context => new StartupTest(context.Configuration, typeof(OptionsValidationException), $"Module file testdata/modules{Path.DirectorySeparatorChar}dontexist.wasm not found for module name dontexist\r\n"));
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsRouteIsMissingConfig.json", mockLoggerFactory, context => new StartupTest(context.Configuration, typeof(OptionsValidationException), $"Route should not be null or empty for module name noroute{Environment.NewLine}"));
testServer.CreateClient();
}

[Fact]
public async Task Test_Handles_Configuration_With_Custom_Section_Name()
{
var mockLogger = new Mock<ILogger>();

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsCustomSectionNameConfig.json", mockLoggerFactory, context => new StartupTest(context.Configuration, "custom"));
Expand All @@ -99,10 +103,9 @@ public async Task Test_Handles_Configuration_With_Custom_Section_Name()
public void Test_Handles_Modules_Directory_Does_Not_Exist()
{
var mockLogger = new Mock<ILogger>();

var mockLoggerFactory = new Mock<ILoggerFactory>();
mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(() => mockLogger.Object);
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsModulesDirectoryDoesNotExistsConfig.json", mockLoggerFactory, context => new StartupTest(context.Configuration, typeof(OptionsValidationException), $"Module Path not found dontexist\r\nModule file dontexist{Path.DirectorySeparatorChar}fibonacci.wasm not found for module name fibonacci\r\n"));
var testServer = EndpointRouteBuilderExtensionsTest.CreateTestServer("testdata/appsettingsModulesDirectoryDoesNotExistsConfig.json", mockLoggerFactory, context => new StartupTest(context.Configuration, typeof(OptionsValidationException), $"Module Path not found dontexist{Environment.NewLine}Module file dontexist{Path.DirectorySeparatorChar}fibonacci.wasm not found for module name fibonacci{Environment.NewLine}"));
testServer.CreateClient();
}

Expand Down
10 changes: 10 additions & 0 deletions source/wagi.test/testdata/appsettingsRouteIsMissingConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Wagi": {
"ModulePath": "testdata/modules",
"Modules": {
"noroute": {
"FileName": "module.wasm"
}
}
}
}
1 change: 1 addition & 0 deletions source/wagi.test/wagi.test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Content Include="testdata\appsettingsModuleIsMissingConfig.json" />
<Content Include="testdata\appsettingsModulesDirectoryDoesNotExistsConfig.json" />
<Content Include="testdata\appsettingsNoConfig.json" />
<Content Include="testdata\appsettingsRouteIsMissingConfig.json" />
<Content Include="testdata\appsettingsWAGIConfig.json" />
<Content Include="testdata\appsettingsWATConfig.json" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions source/wagi/Configuration/ValidateConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public ValidateOptionsResult Validate(string name, WagiModules options)
if (string.IsNullOrEmpty(route))
{
result.AppendLine($"Route should not be null or empty for module name {moduleName}");
return ValidateOptionsResult.Fail(result.ToString());
}

if (route.Contains("{", StringComparison.InvariantCulture) && route.Contains("}", StringComparison.InvariantCulture))
Expand Down Expand Up @@ -137,6 +138,7 @@ public ValidateOptionsResult Validate(string name, WagiModules options)
if (string.IsNullOrEmpty(route))
{
result.AppendLine($"Route should not be null or empty for bindle {bindleName}");
return ValidateOptionsResult.Fail(result.ToString());
}

if (route.Contains("{", StringComparison.InvariantCulture) && route.Contains("}", StringComparison.InvariantCulture))
Expand Down

0 comments on commit 488e009

Please sign in to comment.