From d849e9c1e36e43d79237b04deb37249a4cec3c2b Mon Sep 17 00:00:00 2001 From: Alex Hyett Date: Mon, 10 Jul 2023 14:48:10 +0100 Subject: [PATCH] Add configurable URL --- .env | 2 ++ .github/workflows/build-and-test.yml | 2 ++ .vscode/settings.json | 7 ++++++- README.md | 4 ++++ docker-compose.yml | 2 +- ...itHubActionsDemo.Api.Integration.Tests.csproj | 2 ++ .../IntegrationTests.cs | 16 +++++++++++++--- .../Startup.cs | 16 ++++++++++++++++ 8 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 .env create mode 100644 test/GitHubActionsDemo.Api.Integration.Tests/Startup.cs diff --git a/.env b/.env new file mode 100644 index 0000000..e8291ec --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +BASE_URL=http://localhost:5275 +VERSION=0.1.0 \ No newline at end of file diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 23abfbe..a2b38b7 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -39,6 +39,8 @@ jobs: shell: bash - name: Run Integration Tests run: dotnet test --filter Category=Integration --no-restore --verbosity normal + env: + BASE_URL: http://localhost:5200 - name: Copy Integration Test Results run: cp test/**/TestResults/*.Integration.Tests.trx TestResults/ shell: bash diff --git a/.vscode/settings.json b/.vscode/settings.json index 6abb0ba..218a2dc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,8 @@ { - "dotnet.defaultSolution": "GitHubActionsDemo.sln" + "dotnet.defaultSolution": "GitHubActionsDemo.sln", + "csharp.unitTestDebuggingOptions": { + "env": { + "BASE_URL": "http://localhost:5275", + } +} } diff --git a/README.md b/README.md index 44dbeac..ec022bb 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # Setup a CI/CD Pipeline Using GitHub Actions The code from my YouTube video on "Setup a CI/CD Pipeline Using GitHub Actions" + +The purpose of this project is to show how you can use GitHub actions for CI/CD pipelines. + +This project includes \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index def549b..9e18075 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: depends_on: - db ports: - - '5275:5275' + - '5200:5275' environment: - ASPNETCORE_URLS=http://*:5275 - API_DbSettings__ConnectionString=Server=db;Database=library;Uid=dbuser;Pwd=libraryDbPassword; diff --git a/test/GitHubActionsDemo.Api.Integration.Tests/GitHubActionsDemo.Api.Integration.Tests.csproj b/test/GitHubActionsDemo.Api.Integration.Tests/GitHubActionsDemo.Api.Integration.Tests.csproj index da0bf24..449a5b1 100644 --- a/test/GitHubActionsDemo.Api.Integration.Tests/GitHubActionsDemo.Api.Integration.Tests.csproj +++ b/test/GitHubActionsDemo.Api.Integration.Tests/GitHubActionsDemo.Api.Integration.Tests.csproj @@ -10,9 +10,11 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/test/GitHubActionsDemo.Api.Integration.Tests/IntegrationTests.cs b/test/GitHubActionsDemo.Api.Integration.Tests/IntegrationTests.cs index 2a9b23a..7d4f868 100644 --- a/test/GitHubActionsDemo.Api.Integration.Tests/IntegrationTests.cs +++ b/test/GitHubActionsDemo.Api.Integration.Tests/IntegrationTests.cs @@ -1,16 +1,26 @@ using GitHubActionsDemo.Api.Sdk.Authors; using GitHubActionsDemo.Api.Sdk.Books; +using Microsoft.Extensions.Configuration; using Refit; using Shouldly; +using Xunit.Sdk; namespace GitHubActionsDemo.Api.Integration.Tests; [Trait("Category", "Integration")] public class IntegrationTests { - private const string BaseUri = "http://localhost:5275"; - private readonly IAuthorApi _authorApi = RestService.For(BaseUri); - private readonly IBookApi _bookApi = RestService.For(BaseUri); + public readonly IConfiguration _config; + private readonly IAuthorApi _authorApi; + private readonly IBookApi _bookApi; + + public IntegrationTests(IConfiguration config) + { + _config = config ?? throw new ArgumentNullException(nameof(config)); + var baseUrl = _config.GetValue("BASE_URL"); + _authorApi = RestService.For(baseUrl); + _bookApi = RestService.For(baseUrl); + } [Fact] public async Task Given_valid_author_should_create_author() diff --git a/test/GitHubActionsDemo.Api.Integration.Tests/Startup.cs b/test/GitHubActionsDemo.Api.Integration.Tests/Startup.cs new file mode 100644 index 0000000..b973856 --- /dev/null +++ b/test/GitHubActionsDemo.Api.Integration.Tests/Startup.cs @@ -0,0 +1,16 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; + +namespace GitHubActionsDemo.Api.Integration.Tests; + +public class Startup +{ + public void ConfigureHost(IHostBuilder hostBuilder) + { + var config = new ConfigurationBuilder() + .AddEnvironmentVariables() + .Build(); + + hostBuilder.ConfigureHostConfiguration(builder => builder.AddConfiguration(config)); + } +} \ No newline at end of file