Skip to content

Commit d245c39

Browse files
committed
Remove JSON examples from artifacts
Closes #440 Signed-off-by: Yasumasa Suenaga <[email protected]>
1 parent a9412ac commit d245c39

File tree

20 files changed

+85
-83
lines changed

20 files changed

+85
-83
lines changed

.github/workflows/1-pr.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ jobs:
122122
directory: ${{ env.DOTNET_SRC_DIR }}
123123

124124
- name: Generate Open API
125-
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
126125
env:
126+
DataSources__EmissionsDataSource: Json
127+
DataSources__Configurations__Json__Type: JSON
127128
DOTNET_ROLL_FORWARD: LatestMajor
129+
run: dotnet tool run swagger tofile --output ./wwwroot/api/v1/swagger.yaml --yaml ${{ env.DLL_FILE_PATH }} v1
128130
working-directory: ./src/CarbonAware.WebApi/src
129131

130132
- name: Upload swagger artifact
@@ -146,7 +148,7 @@ jobs:
146148

147149
- name: Docker Run Container
148150
run: |
149-
docker run -d --name runnable-container -p 8080:8080 ca-api
151+
docker run -d --name runnable-container -e DataSources__EmissionsDataSource=Json -e DataSources__Configurations__Json__Type=JSON -p 8080:8080 ca-api
150152
docker container ls
151153
152154
- name: Docker WGET Health Endpoint

src/CarbonAware.CLI/test/integrationTests/CarbonAware.CLI.IntegrationTests.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@
2525
Include="..\..\..\CarbonAware.DataSources\CarbonAware.DataSources.ElectricityMapsFree\mock\CarbonAware.DataSources.ElectricityMapsFree.Mocks.csproj" />
2626
<ProjectReference Include="..\..\src\CarbonAware.CLI.csproj" />
2727
</ItemGroup>
28-
</Project>
28+
29+
<Target Name="CopyDataFiles" AfterTargets="Build">
30+
<Copy SourceFiles="$(ProjectDir)..\..\..\data\data-sources\test-data-azure-emissions.json"
31+
DestinationFiles="$(TargetDir)\data-sources\json\demo.json" SkipUnchangedFiles="true" />
32+
<Copy SourceFiles="$(ProjectDir)..\..\..\data\location-sources\azure-regions.json"
33+
DestinationFiles="$(TargetDir)\location-sources\json\azure-regions.json" SkipUnchangedFiles="true" />
34+
</Target>
35+
36+
</Project>

src/CarbonAware.CLI/test/integrationTests/IntegrationTestingBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public void Setup()
100100
{
101101
Environment.SetEnvironmentVariable("DataSources__EmissionsDataSource", "Json");
102102
Environment.SetEnvironmentVariable("DataSources__Configurations__Json__Type", "JSON");
103+
Environment.SetEnvironmentVariable("DataSources__Configurations__Json__DataFileLocation", "test-data-azure-emissions.json");
103104
_dataSourceMocker = new JsonDataSourceMocker();
104105
break;
105106
}

src/CarbonAware.DataSources/CarbonAware.DataSources.ElectricityMapsFree/mock/CarbonAware.DataSources.ElectricityMapsFree.Mocks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
</ItemGroup>
1616

1717
<ItemGroup>
18+
<InternalsVisibleTo Include="CarbonAware.WebApi.IntegrationTests" />
1819
<InternalsVisibleTo Include="CarbonAware.CLI.IntegrationTests" />
1920
</ItemGroup>
2021

src/CarbonAware.DataSources/CarbonAware.DataSources.Json/mock/JsonDataSourceMocker.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
namespace CarbonAware.DataSources.Json.Mocks;
77
public class JsonDataSourceMocker : IDataSourceMocker
88
{
9-
public JsonDataSourceMocker() { }
9+
10+
public string DataFileName { get; set; }
11+
12+
public JsonDataSourceMocker() {
13+
DataFileName = "test-data-azure-emissions.json";
14+
}
1015

1116
public void SetupDataMock(DateTimeOffset start, DateTimeOffset end, string location)
1217
{
13-
string path = new JsonDataSourceConfiguration().DataFileLocation;
18+
var config = new JsonDataSourceConfiguration();
19+
config.DataFileLocation = DataFileName;
20+
string path = config.DataFileLocation;
1421

1522
var data = new List<EmissionsData>();
1623
DateTimeOffset pointTime = start;

src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/CarbonAware.DataSources.Json.csproj

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

10-
<ItemGroup>
11-
<Content Include="$(ProjectDir)..\..\..\data\data-sources\**\*.json"
12-
Link="\data-sources\json\%(RecursiveDir)%(Filename)%(Extension)">
13-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
14-
</Content>
15-
</ItemGroup>
16-
1710
<ItemGroup>
1811
<InternalsVisibleTo Include="CarbonAware.DataSources.Json.Mocks" />
1912
<InternalsVisibleTo Include="CarbonAware.DataSources.Json.Tests" />
@@ -24,4 +17,8 @@
2417
<ItemGroup>
2518
<ProjectReference Include="..\..\..\CarbonAware\src\CarbonAware.csproj" />
2619
</ItemGroup>
27-
</Project>
20+
21+
<Target Name="CreateDatasourceDirectory" AfterTargets="Build">
22+
<MakeDir Directories="$(PublishDir)\data-sources\json" />
23+
</Target>
24+
</Project>

src/CarbonAware.DataSources/CarbonAware.DataSources.Json/src/Configuration/JsonDataSourceConfiguration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace CarbonAware.DataSources.Json.Configuration;
99
internal class JsonDataSourceConfiguration
1010
{
1111
private const string BaseDirectory = "data-sources/json";
12-
private const string DefaultDataFile = "test-data-azure-emissions.json";
1312
private const string DirectoryRegExPattern = @"^(?!\.{2})[-\\/a-zA-Z_\d\.: ]*$";
1413
private string assemblyDirectory;
1514
private string? dataFileLocation;
@@ -36,7 +35,6 @@ public JsonDataSourceConfiguration()
3635
{
3736
var assemblyPath = Assembly.GetExecutingAssembly().Location;
3837
assemblyDirectory = Path.GetDirectoryName(assemblyPath)!;
39-
DataFileLocation = DefaultDataFile;
4038
CacheJsonData = true;
4139
}
4240

src/CarbonAware.DataSources/CarbonAware.DataSources.Json/test/CarbonAware.DataSources.Json.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@
2727
<ProjectReference Include="..\src\CarbonAware.DataSources.Json.csproj" />
2828
</ItemGroup>
2929

30+
<Target Name="CreateDatasourceDirectory" AfterTargets="Build">
31+
<MakeDir Directories="$(TargetDir)\data-sources\json" />
32+
</Target>
3033
</Project>

src/CarbonAware.DataSources/CarbonAware.DataSources.Json/test/JsonDataSourceConfigurationTests.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ public void Setup()
2424
AssemblyPath = Assembly.GetExecutingAssembly().Location;
2525
}
2626

27-
[Test]
28-
public void GetDefaultDataFileLocation_IsNotNull_ExpectedBaseDir()
29-
{
30-
Assert.That(_configuration.DataFileLocation, Is.Not.Null);
31-
var expectedDir = Path.Combine(Path.GetDirectoryName(AssemblyPath)!, BaseDir);
32-
Assert.That(_configuration.DataFileLocation, Contains.Substring(expectedDir));
33-
}
34-
3527
[TestCase("../newfile.json", TestName = "setting parent's dir")]
3628
[TestCase("~/newfile.json", TestName = "setting user's home dir")]
3729
[TestCase(null, TestName = "setting null filepath")]

src/CarbonAware.DataSources/CarbonAware.DataSources.Json/test/JsonDataSourceTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,16 @@ public async Task GetCarbonIntensityAsync_ReturnsEmptyEmissionData()
111111
public async Task GetCarbonIntensityAsync_CacheEmissionData(bool cache)
112112
{
113113
var logger = Mock.Of<ILogger<JsonDataSource>>();
114-
115114
var monitor = new Mock<IOptionsMonitor<JsonDataSourceConfiguration>>();
115+
JsonDataSourceMocker dsMocker = new();
116116
var config = new JsonDataSourceConfiguration
117117
{
118+
DataFileLocation = dsMocker.DataFileName,
118119
CacheJsonData = cache
119120
};
120121
monitor.Setup(m => m.CurrentValue).Returns(config);
121122
var dataSource = new JsonDataSource(logger, monitor.Object);
122123

123-
JsonDataSourceMocker dsMocker = new();
124-
125124
var today = DateTimeOffset.Now;
126125
var todayEnd = today.AddMinutes(30);
127126
var todayLocation = new Location() { Name = "japan" };

0 commit comments

Comments
 (0)