From 792e427629d0cd6cc3b44c2272249441a39818cf Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Sun, 18 Oct 2026 13:25:39 +0200 Subject: [PATCH] build(deps): adopt shared archera comparison contract --- go.mod | 2 +- go.sum | 4 +- tools/archera_pkg_adoption_test.go | 62 +++++++++++++++++++++ tools/testdata/archera_comparison_wire.json | 3 + 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tools/archera_pkg_adoption_test.go diff --git a/go.mod b/go.mod index 461f7ff..1751285 100644 --- a/go.mod +++ b/go.mod @@ -74,7 +74,7 @@ require ( ) require ( - github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261012130811-9dae64b216d4 + github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261016175124-570d168c6bc7 github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261012130811-9dae64b216d4 github.com/LeanerCloud/cloud-commitments-go/providers/azure v0.0.0-20261012130811-9dae64b216d4 github.com/LeanerCloud/cloud-commitments-go/providers/gcp v0.0.0-20261012130811-9dae64b216d4 diff --git a/go.sum b/go.sum index 9d829ba..7596533 100644 --- a/go.sum +++ b/go.sum @@ -76,8 +76,8 @@ github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0 github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/cloudmock v0.55.0/go.mod h1:vB2GH9GAYYJTO3mEn8oYwzEdhlayZIdQz6zdzgUIRvA= github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.55.0 h1:0s6TxfCu2KHkkZPnBfsQ2y5qia0jl3MMrmBhu3nCOYk= github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.55.0/go.mod h1:Mf6O40IAyB9zR/1J8nGDDPirZQQPbYJni8Yisy7NTMc= -github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261012130811-9dae64b216d4 h1:4C/4ZLemkgC45z47LtCjICglnfcTBzP2KUAq/gZEzZQ= -github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261012130811-9dae64b216d4/go.mod h1:8RTmzPazA8IeVZfn7wNaU7ILx0VK5eHZQozO21Mvtq8= +github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261016175124-570d168c6bc7 h1:mAvqQSMkTuw4P8m8o+/wdyoxGE9L6eiEzZFanGXqYcI= +github.com/LeanerCloud/cloud-commitments-go/pkg v0.0.0-20261016175124-570d168c6bc7/go.mod h1:SCDEgHG6evjPh0RsoXof+J3aMmGXNFMrwbJIle7rMpQ= github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261012130811-9dae64b216d4 h1:fnEv+2eCL0ObXn1nAFlBa2kZy1A0/nhc7LxYeDFCCkQ= github.com/LeanerCloud/cloud-commitments-go/providers/aws v0.0.0-20261012130811-9dae64b216d4/go.mod h1:C0ildZeRds0aRvDZp49MLY0kFWh/4FiM4lPWWWd3HFA= github.com/LeanerCloud/cloud-commitments-go/providers/azure v0.0.0-20261012130811-9dae64b216d4 h1:HljKKZOmfam4C3T5109DMeUQuyxVHRohroA4j/OU5oY= diff --git a/tools/archera_pkg_adoption_test.go b/tools/archera_pkg_adoption_test.go new file mode 100644 index 0000000..84aefe8 --- /dev/null +++ b/tools/archera_pkg_adoption_test.go @@ -0,0 +1,62 @@ +package tools + +import ( + "encoding/json" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestArcheraComparisonSelectedAmountContract(t *testing.T) { + setArcheraEnv(t) + cases := []struct { + value any + name string + missing bool + invalid bool + }{ + {name: "missing", missing: true, invalid: true}, + {name: "null", invalid: true}, + {name: "negative", value: json.Number("-0.01"), invalid: true}, + {name: "zero", value: json.Number("0")}, + {name: "positive", value: json.Number("2")}, + } + for _, location := range []struct { + name string + candidate int + }{{name: "current", candidate: -1}, {name: "first candidate", candidate: 0}, {name: "second candidate", candidate: 1}} { + for _, tc := range cases { + t.Run(location.name+"/"+tc.name, func(t *testing.T) { + var wire map[string]any + require.NoError(t, json.Unmarshal(readWire(t), &wire)) + entry := entryOf(wire) + if location.candidate >= 0 { + row := wire["data"].([]any)[0].(map[string]any) + entry = row["candidates"].([]any)[location.candidate].(map[string]any) + } + if tc.missing { + delete(entry, "selected_amount") + } else { + entry["selected_amount"] = tc.value + } + body, err := json.Marshal(wire) + require.NoError(t, err) + transport := okTransport(body) + result, protocol, err := callArchera(t, transport, nil) + require.NoError(t, err) + require.NotNil(t, result) + assert.Equal(t, 1, transport.count()) + assert.NotContains(t, protocol, testArcheraKey) + if tc.invalid { + require.True(t, result.IsError, "invalid selected_amount must be refused") + assert.Contains(t, resultText(result), "selected_amount") + assert.Empty(t, result.StructuredContent) + } else { + got := structured(t, result) + assert.Len(t, got["rows"], 1) + } + }) + } + } +} diff --git a/tools/testdata/archera_comparison_wire.json b/tools/testdata/archera_comparison_wire.json index 6ba01b1..8a20767 100644 --- a/tools/testdata/archera_comparison_wire.json +++ b/tools/testdata/archera_comparison_wire.json @@ -80,6 +80,7 @@ "current": { "is_current": true, "offer_id": "offer-cur", + "selected_amount": 2, "offer": { "provider": "aws", "region": "eu-west-1", @@ -118,6 +119,7 @@ "candidates": [ { "is_current": false, + "selected_amount": 2, "offer_id": "\u001b[31m\u009b\u0085\u200b\u2028HOSTILE_OFFERID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "offer": { "provider": "gcp", @@ -157,6 +159,7 @@ { "is_current": false, "offer_id": "offer-c2", + "selected_amount": 0.125, "offer": { "provider": "aws", "region": null,