Skip to content

Commit

Permalink
Fix parsing VM price
Browse files Browse the repository at this point in the history
C# was expecting properties to be pascal case.
  • Loading branch information
gabrielweyer committed Oct 12, 2024
1 parent 20332ce commit 6cfd045
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 61 deletions.
122 changes: 62 additions & 60 deletions coster/.nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,63 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"$ref": "#/definitions/build",
"title": "Build Schema",
"properties": {
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Debug",
"Release"
]
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
}
},
"definitions": {
"build": {
"type": "object",
"Host": {
"type": "string",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
},
"ExecutableTarget": {
"type": "string",
"enum": [
"Clean",
"Compile",
"GenerateCoverage",
"Restore",
"Test",
"VerifyFormat"
]
},
"Verbosity": {
"type": "string",
"description": "",
"enum": [
"Verbose",
"Normal",
"Minimal",
"Quiet"
]
},
"NukeBuild": {
"properties": {
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Debug",
"Release"
]
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
Expand All @@ -23,25 +67,8 @@
"description": "Shows the help text for this build assembly"
},
"Host": {
"type": "string",
"description": "Host for execution. Default is 'automatic'",
"enum": [
"AppVeyor",
"AzurePipelines",
"Bamboo",
"Bitbucket",
"Bitrise",
"GitHubActions",
"GitLab",
"Jenkins",
"Rider",
"SpaceAutomation",
"TeamCity",
"Terminal",
"TravisCI",
"VisualStudio",
"VSCode"
]
"$ref": "#/definitions/Host"
},
"NoLogo": {
"type": "boolean",
Expand Down Expand Up @@ -70,47 +97,22 @@
"type": "array",
"description": "List of targets to be skipped. Empty list skips all dependencies",
"items": {
"type": "string",
"enum": [
"Clean",
"Compile",
"GenerateCoverage",
"Restore",
"Test",
"VerifyFormat"
]
"$ref": "#/definitions/ExecutableTarget"
}
},
"Solution": {
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
"items": {
"type": "string",
"enum": [
"Clean",
"Compile",
"GenerateCoverage",
"Restore",
"Test",
"VerifyFormat"
]
"$ref": "#/definitions/ExecutableTarget"
}
},
"Verbosity": {
"type": "string",
"description": "Logging verbosity during build execution. Default is 'Normal'",
"enum": [
"Minimal",
"Normal",
"Quiet",
"Verbose"
]
"$ref": "#/definitions/Verbosity"
}
}
}
}
},
"$ref": "#/definitions/NukeBuild"
}
7 changes: 6 additions & 1 deletion coster/src/AzureVmCoster/Services/VmPricingParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ public List<VmPricing> Parse()

var allVmPricing = new List<VmPricing>();

JsonSerializerOptions options = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};

foreach (var pricingFile in pricingFiles)
{
var fileInfo = new FileInfo(pricingFile);
var fileIdentifier = FileIdentifier.From(fileInfo);

var fileVmPricing = JsonSerializer.Deserialize<List<VmPricing>>(File.ReadAllText(pricingFile));
var fileVmPricing = JsonSerializer.Deserialize<List<VmPricing>>(File.ReadAllText(pricingFile), options);

if (fileVmPricing == null || fileVmPricing.Count == 0)
{
Expand Down
6 changes: 6 additions & 0 deletions coster/tests/AzureVmCosterTests/AzureVmCosterTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@
</None>
</ItemGroup>

<ItemGroup>
<None Update="TestPricing\*.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions coster/tests/AzureVmCosterTests/Services/VmPricingParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using AzureVmCoster.Services;

namespace AzureVmCosterTests.Services;

public class VmPricingParserTests
{
private readonly VmPricingParser _parser = new("TestPricing/");

[Fact]
public void GivenValidPrice_ThenParseVm()
{
// Act
var prices = _parser.Parse();

// Assert
var expectedPrices = new List<VmPricing>
{
new()
{
Region = "germany-west-central",
OperatingSystem = "windows",
Instance = "B2ts v2",
VCpu = 2,
Ram = 1,
PayAsYouGo = 0.019m,
PayAsYouGoWithAzureHybridBenefit = 0.0107m,
OneYearSavingsPlan = 0.0153m,
OneYearSavingsPlanWithAzureHybridBenefit = 0.0082m,
ThreeYearSavingsPlan = 0.0131m,
ThreeYearSavingsPlanWithAzureHybridBenefit = 0.0059m,
OneYearReserved = 0.0135m,
OneYearReservedWithAzureHybridBenefit = 0.0063m,
ThreeYearReserved = 0.0113m,
ThreeYearReservedWithAzureHybridBenefit = 0.0041m,
Spot = 0.0063m,
SpotWithAzureHybridBenefit = 0.0036m
}
};
prices.Should().BeEquivalentTo(expectedPrices);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"instance": "B2ts v2",
"vCpu": 2,
"ram": 1,
"payAsYouGo": 0.019,
"payAsYouGoWithAzureHybridBenefit": 0.0107,
"oneYearSavingsPlan": 0.0153,
"oneYearSavingsPlanWithAzureHybridBenefit": 0.0082,
"threeYearSavingsPlan": 0.0131,
"threeYearSavingsPlanWithAzureHybridBenefit": 0.0059,
"oneYearReserved": 0.0135,
"oneYearReservedWithAzureHybridBenefit": 0.0063,
"threeYearReserved": 0.0113,
"threeYearReservedWithAzureHybridBenefit": 0.0041,
"spot": 0.0063,
"spotWithAzureHybridBenefit": 0.0036
}
]

0 comments on commit 6cfd045

Please sign in to comment.