diff --git a/cmd/audit_recurring_cost_test.go b/cmd/audit_recurring_cost_test.go new file mode 100644 index 000000000..5bcd36851 --- /dev/null +++ b/cmd/audit_recurring_cost_test.go @@ -0,0 +1,31 @@ +package main + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/LeanerCloud/cloud-commitments-go/pkg/common" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestWritePurchaseAuditRecord_SavingsPlanCarriesRecurringMonthlyCost(t *testing.T) { + recurring := 1968.81 + rec := common.Recommendation{ + Provider: common.ProviderAWS, Service: common.ServiceSavingsPlansEC2Instance, + CommitmentType: common.CommitmentSavingsPlan, Term: "1yr", PaymentOption: "no-upfront", + Count: 1, RecurringMonthlyCost: &recurring, + } + path := filepath.Join(t.TempDir(), "audit.jsonl") + + require.NoError(t, writePurchaseAuditRecord("run-1", rec, common.PurchaseResult{Recommendation: rec}, "skipped", true, path)) + + data, err := os.ReadFile(path) + require.NoError(t, err) + var line map[string]any + require.NoError(t, json.Unmarshal(data, &line)) + assert.Equal(t, 0.0, line["estimated_cost"], "upfront stays where it was") + assert.Equal(t, 1968.81, line["recurring_monthly_cost"]) +} diff --git a/go.mod b/go.mod index fc9b593be..9f915c246 100644 --- a/go.mod +++ b/go.mod @@ -82,8 +82,8 @@ require ( require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.2.0 - github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261013183209-f794d75afb69 - github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261013183209-f794d75afb69 + github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261013184038-e9a33bb14d0d + github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261013184038-e9a33bb14d0d github.com/LeanerCloud/cloud-commitments-go/providers/azure v0.0.0-20261007133317-58c25f04c49b github.com/LeanerCloud/cloud-commitments-go/providers/gcp v0.0.0-20261006205158-7ff8c1aee1bb github.com/aws/aws-sdk-go-v2/service/organizations v1.45.3 diff --git a/go.sum b/go.sum index a695a6583..a2f4806a1 100644 --- a/go.sum +++ b/go.sum @@ -78,10 +78,10 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0 github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.54.0/go.mod h1:vB2GH9GAYYJTO3mEn8oYwzEdhlayZIdQz6zdzgUIRvA= github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.54.0 h1:s0WlVbf9qpvkh1c/uDAPElam0WrL7fHRIidgZJ7UqZI= github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.54.0/go.mod h1:Mf6O40IAyB9zR/1J8nGDDPirZQQPbYJni8Yisy7NTMc= -github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261013183209-f794d75afb69 h1:MHTNQEtRh+K6OcCJlETArAB8G/RWRC4eGqcWlhMZplk= -github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261013183209-f794d75afb69/go.mod h1:8RTmzPazA8IeVZfn7wNaU7ILx0VK5eHZQozO21Mvtq8= -github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261013183209-f794d75afb69 h1:Ra+eyZPRa/R1YcTPVnPR3o/ywDs8TO+UuPJ8W+tck7A= -github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261013183209-f794d75afb69/go.mod h1:no7i/7i+W37+qhEOVU8F/0dP5FhO3wtzvKIN0+tvL3A= +github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261013184038-e9a33bb14d0d h1:LzTtaDpdS0FJJ0x9kRbrrn4Zrm85HLccnO9L8Wp8toc= +github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261013184038-e9a33bb14d0d/go.mod h1:8RTmzPazA8IeVZfn7wNaU7ILx0VK5eHZQozO21Mvtq8= +github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261013184038-e9a33bb14d0d h1:NlNTNHOpftHUfSNmVJKAHhA6RP0uLRJOAlk8xmhJjy8= +github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261013184038-e9a33bb14d0d/go.mod h1:no7i/7i+W37+qhEOVU8F/0dP5FhO3wtzvKIN0+tvL3A= github.com/LeanerCloud/cloud-commitments-go/providers/azure v0.0.0-20261007133317-58c25f04c49b h1:yurugmfdZjf+dqjfqfDyfoBR3IAiFUpMKQ8URnZnJzQ= github.com/LeanerCloud/cloud-commitments-go/providers/azure v0.0.0-20261007133317-58c25f04c49b/go.mod h1:iIvPuWLWd+SXqLHAQNdodYMUAAcq7PnwfScXWgARt5A= github.com/LeanerCloud/cloud-commitments-go/providers/gcp v0.0.0-20261006205158-7ff8c1aee1bb h1:AJ4nKDtttjiTDemo9PDp2esoc35ymVaiCSr0zIewwpY=