From 5eeb08b2c6d4c1f15a9f490f900a8320d1a431af Mon Sep 17 00:00:00 2001 From: Yasumasa Suenaga Date: Sun, 21 Jan 2024 22:20:29 +0900 Subject: [PATCH] Remove JSON examples from artifacts Closes #440 Signed-off-by: Yasumasa Suenaga --- .../CarbonAware.CLI.IntegrationTests.csproj | 10 +++++++++- .../IntegrationTestingBase.cs | 1 + .../mock/JsonDataSourceMocker.cs | 4 +++- .../src/CarbonAware.DataSources.Json.csproj | 13 +++++-------- .../JsonDataSourceConfiguration.cs | 2 -- .../test/JsonDataSourceConfigurationTests.cs | 8 -------- .../src/CarbonAware.LocationSources.csproj | 13 +++++-------- src/CarbonAware.WebApi/src/Dockerfile | 3 +++ src/CarbonAware.WebApi/src/appsettings.json | 10 ---------- ...CarbonAware.WebApi.IntegrationTests.csproj | 4 +++- .../CarbonAwareControllerTests.cs | 2 +- .../LocationsControllerTests.cs | 2 +- ...dWebApiTests.cs => WebApiEndpointTests.cs} | 8 ++++---- .../src/GSF.CarbonAware.csproj | 5 +---- .../src/GSF.CarbonAware.targets | 19 +++---------------- 15 files changed, 39 insertions(+), 65 deletions(-) rename src/CarbonAware.WebApi/test/integrationTests/{UnconfiguredWebApiTests.cs => WebApiEndpointTests.cs} (77%) diff --git a/src/CarbonAware.CLI/test/integrationTests/CarbonAware.CLI.IntegrationTests.csproj b/src/CarbonAware.CLI/test/integrationTests/CarbonAware.CLI.IntegrationTests.csproj index 9b0dd0efe..b391e0cab 100644 --- a/src/CarbonAware.CLI/test/integrationTests/CarbonAware.CLI.IntegrationTests.csproj +++ b/src/CarbonAware.CLI/test/integrationTests/CarbonAware.CLI.IntegrationTests.csproj @@ -25,4 +25,12 @@ Include="..\..\..\CarbonAware.DataSources\CarbonAware.DataSources.ElectricityMapsFree\mock\CarbonAware.DataSources.ElectricityMapsFree.Mocks.csproj" /> - \ No newline at end of file + + + + + + + diff --git a/src/CarbonAware.CLI/test/integrationTests/IntegrationTestingBase.cs b/src/CarbonAware.CLI/test/integrationTests/IntegrationTestingBase.cs index 1ab6b9d40..120ce2f80 100644 --- a/src/CarbonAware.CLI/test/integrationTests/IntegrationTestingBase.cs +++ b/src/CarbonAware.CLI/test/integrationTests/IntegrationTestingBase.cs @@ -100,6 +100,7 @@ public void Setup() { Environment.SetEnvironmentVariable("DataSources__EmissionsDataSource", "Json"); Environment.SetEnvironmentVariable("DataSources__Configurations__Json__Type", "JSON"); + Environment.SetEnvironmentVariable("DataSources__Configurations__Json__DataFileLocation", "test-data-azure-emissions.json"); _dataSourceMocker = new JsonDataSourceMocker(); break; } diff --git a/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/mock/JsonDataSourceMocker.cs b/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/mock/JsonDataSourceMocker.cs index ee7bf4ba5..fb78a9ee2 100644 --- a/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/mock/JsonDataSourceMocker.cs +++ b/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/mock/JsonDataSourceMocker.cs @@ -10,7 +10,9 @@ internal class JsonDataSourceMocker : IDataSourceMocker public void SetupDataMock(DateTimeOffset start, DateTimeOffset end, string location) { - string path = new JsonDataSourceConfiguration().DataFileLocation; + var config = new JsonDataSourceConfiguration(); + config.DataFileLocation = "test-data-azure-emissions.json"; + string path = config.DataFileLocation; var data = new List(); DateTimeOffset pointTime = start; diff --git a/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/CarbonAware.DataSources.Json.csproj b/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/CarbonAware.DataSources.Json.csproj index 7c9905d41..5c9ff6c04 100644 --- a/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/CarbonAware.DataSources.Json.csproj +++ b/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/CarbonAware.DataSources.Json.csproj @@ -7,13 +7,6 @@ false - - - Always - - - @@ -24,4 +17,8 @@ - \ No newline at end of file + + + + + diff --git a/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/Configuration/JsonDataSourceConfiguration.cs b/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/Configuration/JsonDataSourceConfiguration.cs index 2c69e6be8..1805342b5 100644 --- a/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/Configuration/JsonDataSourceConfiguration.cs +++ b/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/Configuration/JsonDataSourceConfiguration.cs @@ -9,7 +9,6 @@ namespace CarbonAware.DataSources.Json.Configuration; internal class JsonDataSourceConfiguration { private const string BaseDirectory = "data-sources/json"; - private const string DefaultDataFile = "test-data-azure-emissions.json"; private const string DirectoryRegExPattern = @"^(?!\.{2})[-\\/a-zA-Z_\d\.: ]*$"; private string assemblyDirectory; private string? dataFileLocation; @@ -34,7 +33,6 @@ public JsonDataSourceConfiguration() { var assemblyPath = Assembly.GetExecutingAssembly().Location; assemblyDirectory = Path.GetDirectoryName(assemblyPath)!; - DataFileLocation = DefaultDataFile; } private static bool IsValidDirPath(string fileName) diff --git a/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/test/JsonDataSourceConfigurationTests.cs b/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/test/JsonDataSourceConfigurationTests.cs index f63565a73..e8d0f0cc7 100644 --- a/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/test/JsonDataSourceConfigurationTests.cs +++ b/src/CarbonAware.DataSources/CarbonAware.DataSources.Json/test/JsonDataSourceConfigurationTests.cs @@ -24,14 +24,6 @@ public void Setup() AssemblyPath = Assembly.GetExecutingAssembly().Location; } - [Test] - public void GetDefaultDataFileLocation_IsNotNull_ExpectedBaseDir() - { - Assert.That(_configuration.DataFileLocation, Is.Not.Null); - var expectedDir = Path.Combine(Path.GetDirectoryName(AssemblyPath)!, BaseDir); - Assert.That(_configuration.DataFileLocation, Contains.Substring(expectedDir)); - } - [TestCase("../newfile.json", TestName = "setting parent's dir")] [TestCase("~/newfile.json", TestName = "setting user's home dir")] [TestCase(null, TestName = "setting null filepath")] diff --git a/src/CarbonAware.LocationSources/src/CarbonAware.LocationSources.csproj b/src/CarbonAware.LocationSources/src/CarbonAware.LocationSources.csproj index d05da871e..9f7e2e214 100644 --- a/src/CarbonAware.LocationSources/src/CarbonAware.LocationSources.csproj +++ b/src/CarbonAware.LocationSources/src/CarbonAware.LocationSources.csproj @@ -12,16 +12,13 @@ false - - - Always - - - - \ No newline at end of file + + + + + diff --git a/src/CarbonAware.WebApi/src/Dockerfile b/src/CarbonAware.WebApi/src/Dockerfile index bc46714fe..937227a09 100644 --- a/src/CarbonAware.WebApi/src/Dockerfile +++ b/src/CarbonAware.WebApi/src/Dockerfile @@ -7,6 +7,9 @@ COPY . ./ RUN dotnet publish CarbonAware.WebApi/src/CarbonAware.WebApi.csproj -c Release -o publish # Generate OpenAPI spec WORKDIR /app/CarbonAware.WebApi/src +# Set environment variables for dummy datasource to start "dotnet tool run" +ENV DataSources__EmissionsDataSource=Json +ENV DataSources__Configurations__Json__Type=JSON RUN dotnet tool restore && \ mkdir -p /app/publish/wwwroot/api/v1 && \ dotnet tool run swagger tofile --output /app/publish/wwwroot/api/v1/swagger.yaml --yaml /app/publish/CarbonAware.WebApi.dll v1 diff --git a/src/CarbonAware.WebApi/src/appsettings.json b/src/CarbonAware.WebApi/src/appsettings.json index 8208b3d19..10f68b8c8 100644 --- a/src/CarbonAware.WebApi/src/appsettings.json +++ b/src/CarbonAware.WebApi/src/appsettings.json @@ -1,14 +1,4 @@ { - "DataSources": { - "EmissionsDataSource": "test-json", - "ForecastDataSource": "", // We don't currently publish a sample test data source for forecasts. - "Configurations": { - "test-json": { - "Type": "JSON", - "DataFileLocation": "test-data-azure-emissions.json" - } - } - }, "Logging": { "LogLevel": { "Default": "Information", diff --git a/src/CarbonAware.WebApi/test/integrationTests/CarbonAware.WebApi.IntegrationTests.csproj b/src/CarbonAware.WebApi/test/integrationTests/CarbonAware.WebApi.IntegrationTests.csproj index df1ed5ada..d1d7c47ad 100644 --- a/src/CarbonAware.WebApi/test/integrationTests/CarbonAware.WebApi.IntegrationTests.csproj +++ b/src/CarbonAware.WebApi/test/integrationTests/CarbonAware.WebApi.IntegrationTests.csproj @@ -36,6 +36,8 @@ + - \ No newline at end of file + diff --git a/src/CarbonAware.WebApi/test/integrationTests/CarbonAwareControllerTests.cs b/src/CarbonAware.WebApi/test/integrationTests/CarbonAwareControllerTests.cs index d4954bbd6..86bf21531 100644 --- a/src/CarbonAware.WebApi/test/integrationTests/CarbonAwareControllerTests.cs +++ b/src/CarbonAware.WebApi/test/integrationTests/CarbonAwareControllerTests.cs @@ -15,7 +15,7 @@ namespace CarbonAware.WepApi.IntegrationTests; [TestFixture(DataSourceType.JSON)] [TestFixture(DataSourceType.WattTime)] [TestFixture(DataSourceType.ElectricityMaps)] -[TestFixture(DataSourceType.ElectricityMapsFree)] +//[TestFixture(DataSourceType.ElectricityMapsFree)] // TODO: need to implement data source into IntegrationTestingBase.cs class CarbonAwareControllerTests : IntegrationTestingBase { private readonly string healthURI = "/health"; diff --git a/src/CarbonAware.WebApi/test/integrationTests/LocationsControllerTests.cs b/src/CarbonAware.WebApi/test/integrationTests/LocationsControllerTests.cs index 1a1fd79c1..301ab8d6c 100644 --- a/src/CarbonAware.WebApi/test/integrationTests/LocationsControllerTests.cs +++ b/src/CarbonAware.WebApi/test/integrationTests/LocationsControllerTests.cs @@ -12,7 +12,7 @@ namespace CarbonAware.WepApi.IntegrationTests; [TestFixture(DataSourceType.JSON)] [TestFixture(DataSourceType.WattTime)] [TestFixture(DataSourceType.ElectricityMaps)] -[TestFixture(DataSourceType.ElectricityMapsFree)] +//[TestFixture(DataSourceType.ElectricityMapsFree)] // TODO: need to implement data source into IntegrationTestingBase.cs class LocationsControllerTests : IntegrationTestingBase { private readonly string locationsURI = "/locations"; diff --git a/src/CarbonAware.WebApi/test/integrationTests/UnconfiguredWebApiTests.cs b/src/CarbonAware.WebApi/test/integrationTests/WebApiEndpointTests.cs similarity index 77% rename from src/CarbonAware.WebApi/test/integrationTests/UnconfiguredWebApiTests.cs rename to src/CarbonAware.WebApi/test/integrationTests/WebApiEndpointTests.cs index 665b3884a..6bb55dd74 100644 --- a/src/CarbonAware.WebApi/test/integrationTests/UnconfiguredWebApiTests.cs +++ b/src/CarbonAware.WebApi/test/integrationTests/WebApiEndpointTests.cs @@ -5,15 +5,15 @@ namespace CarbonAware.WebApi.IntegrationTests; /// -/// Tests that the Web API starts without configuration. +/// Tests that static Web API endpoints. /// -[TestFixture(DataSourceType.None)] -class UnconfiguredWebApiTests : IntegrationTestingBase +[TestFixture(DataSourceType.JSON)] +class WebApiEndpointTests : IntegrationTestingBase { private readonly string healthURI = "/health"; private readonly string fakeURI = "/fake-endpoint"; - public UnconfiguredWebApiTests(DataSourceType dataSource) : base(dataSource) { } + public WebApiEndpointTests(DataSourceType dataSource) : base(dataSource) { } [Test] public async Task HealthCheck_ReturnsOK() diff --git a/src/GSF.CarbonAware/src/GSF.CarbonAware.csproj b/src/GSF.CarbonAware/src/GSF.CarbonAware.csproj index f113e0b98..268786977 100644 --- a/src/GSF.CarbonAware/src/GSF.CarbonAware.csproj +++ b/src/GSF.CarbonAware/src/GSF.CarbonAware.csproj @@ -49,12 +49,9 @@ - - - \ No newline at end of file + diff --git a/src/GSF.CarbonAware/src/GSF.CarbonAware.targets b/src/GSF.CarbonAware/src/GSF.CarbonAware.targets index 0e9a1ace2..b0a0e8e83 100644 --- a/src/GSF.CarbonAware/src/GSF.CarbonAware.targets +++ b/src/GSF.CarbonAware/src/GSF.CarbonAware.targets @@ -1,24 +1,11 @@ - - - - - - - - - - - - - - - - + + +