Browse Source

Add frontend-backend test (#89)

pull/92/head
Justin Kotalik 7 years ago
committed by GitHub
parent
commit
19190e79b1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      samples/frontend-backend/backend/Program.cs
  2. 4
      samples/frontend-backend/backend/Startup.cs
  3. 2
      samples/frontend-backend/frontend/ConfigurationExtensions.cs
  4. 2
      samples/frontend-backend/frontend/Program.cs
  5. 4
      samples/frontend-backend/frontend/Startup.cs
  6. 2
      samples/multi-project/backend/Program.cs
  7. 4
      samples/multi-project/backend/Startup.cs
  8. 2
      samples/multi-project/frontend/ConfigurationExtensions.cs
  9. 2
      samples/multi-project/frontend/Pages/Error.cshtml.cs
  10. 2
      samples/multi-project/frontend/Program.cs
  11. 4
      samples/multi-project/frontend/Startup.cs
  12. 2
      samples/multi-project/worker/Program.cs
  13. 4
      samples/multi-project/worker/QueueWorker.cs
  14. 2
      samples/single-project/test-project/Program.cs
  15. 2
      samples/single-project/test-project/Startup.cs
  16. 85
      test/E2ETest/TyeRunTests.cs

2
samples/frontend-backend/backend/Program.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

4
samples/frontend-backend/backend/Startup.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@ -13,7 +13,7 @@ using Microsoft.Extensions.Hosting;
namespace Backend
{
public class Startup
{
{
private readonly JsonSerializerOptions options = new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true,

2
samples/frontend-backend/frontend/ConfigurationExtensions.cs

@ -22,4 +22,4 @@ namespace Microsoft.Extensions.Configuration
return new Uri(protocol + "://" + host + ":" + port + "/");
}
}
}
}

2
samples/frontend-backend/frontend/Program.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

4
samples/frontend-backend/frontend/Startup.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@ -64,7 +64,7 @@ namespace Frontend
await context.Response.WriteAsync($"Backend Listening IP: {backendInfo.IP}{Environment.NewLine}");
await context.Response.WriteAsync($"Backend Hostname: {backendInfo.Hostname}{Environment.NewLine}");
});
endpoints.MapHealthChecks("/healthz");
});
}

2
samples/multi-project/backend/Program.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

4
samples/multi-project/backend/Startup.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@ -21,7 +21,7 @@ namespace Backend
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthorization();

2
samples/multi-project/frontend/ConfigurationExtensions.cs

@ -22,4 +22,4 @@ namespace Microsoft.Extensions.Configuration
return new Uri(protocol + "://" + host + ":" + port + "/");
}
}
}
}

2
samples/multi-project/frontend/Pages/Error.cshtml.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

2
samples/multi-project/frontend/Program.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

4
samples/multi-project/frontend/Startup.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@ -21,7 +21,7 @@ namespace Frontend
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();

2
samples/multi-project/worker/Program.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

4
samples/multi-project/worker/QueueWorker.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
@ -57,7 +57,7 @@ namespace Worker
throw;
}
}
private async Task<IModel> ConnectAsync(CancellationToken cancellationToken)
{
ExceptionDispatchInfo? edi = null;

2
samples/single-project/test-project/Program.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

2
samples/single-project/test-project/Startup.cs

@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

85
test/E2ETest/TyeRunTests.cs

@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
@ -28,7 +29,7 @@ namespace E2ETest
}
[Fact]
public async Task SingleProjectTest()
public async Task SingleProjectRunTest()
{
var projectDirectory = new DirectoryInfo(Path.Combine(TestHelpers.GetSolutionRootDirectory("tye"), "samples", "single-project", "test-project"));
using var tempDirectory = TempDirectory.Create();
@ -96,5 +97,87 @@ namespace E2ETest
await host.StopAsync();
}
}
[Fact]
public async Task FrontendBackendRunTest()
{
var projectDirectory = new DirectoryInfo(Path.Combine(TestHelpers.GetSolutionRootDirectory("tye"), "samples", "frontend-backend"));
using var tempDirectory = TempDirectory.Create();
DirectoryCopy.Copy(projectDirectory.FullName, tempDirectory.DirectoryPath);
var projectFile = new FileInfo(Path.Combine(tempDirectory.DirectoryPath, "tye.yaml"));
var application = ConfigFactory.FromFile(projectFile);
using var host = new TyeHost(application.ToHostingApplication(), Array.Empty<string>())
{
Sink = sink,
};
await host.StartAsync();
try
{
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (a, b, c, d) => true,
AllowAutoRedirect = false
};
var client = new HttpClient(new RetryHandler(handler));
var dashboardUri = new Uri(host.DashboardWebApplication!.Addresses.First());
var dashboardResponse = await client.GetStringAsync(dashboardUri);
await CheckServiceIsUp(application, client, "backend", dashboardUri);
await CheckServiceIsUp(application, client, "frontend", dashboardUri);
}
finally
{
await host.StopAsync();
}
}
private async Task CheckServiceIsUp(ConfigApplication application, HttpClient client, string serviceName, Uri dashboardUri)
{
// make sure backend is up before frontend
var service = application.Services.Where(a => a.Name == serviceName).First();
var binding = service.Bindings.First();
var protocol = binding.Protocol != null && binding.Protocol.Length != 0 ? binding.Protocol : "http";
var hostName = binding.Host != null && binding.Host.Length != 0 ? binding.Host : "localhost";
var uriString = $"{protocol}://{hostName}:{binding.Port}";
// Confirm that the uri is in the dashboard response.
var uriBackendProcess = new Uri(uriString);
// This isn't reliable right now because micronetes only guarantees the process starts, not that
// that kestrel started.
try
{
var appResponse = await client.GetAsync(uriBackendProcess);
Assert.Equal(HttpStatusCode.OK, appResponse.StatusCode);
var content = await appResponse.Content.ReadAsStringAsync();
if (serviceName == "frontend")
{
Assert.Matches("Frontend Listening IP: (.+)\n", content);
Assert.Matches("Backend Listening IP: (.+)\n", content);
}
}
finally
{
// If we failed, there's a good chance the service isn't running. Let's get the logs either way and put
// them in the output.
foreach (var s in application.Services)
{
var request = new HttpRequestMessage(HttpMethod.Get, new Uri(dashboardUri, $"/api/v1/logs/{s.Name}"));
var response = await client.SendAsync(request);
var text = await response.Content.ReadAsStringAsync();
output.WriteLine($"Logs for service: {s.Name}");
output.WriteLine(text);
}
}
}
}
}

Loading…
Cancel
Save