Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
62 changes: 62 additions & 0 deletions tools/archera_pkg_adoption_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
}
3 changes: 3 additions & 0 deletions tools/testdata/archera_comparison_wire.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"current": {
"is_current": true,
"offer_id": "offer-cur",
"selected_amount": 2,
"offer": {
"provider": "aws",
"region": "eu-west-1",
Expand Down Expand Up @@ -118,6 +119,7 @@
"candidates": [
{
"is_current": false,
"selected_amount": 2,
"offer_id": "\u001b[31m\u009b\u0085\u200b\u2028HOSTILE_OFFERID_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"offer": {
"provider": "gcp",
Expand Down Expand Up @@ -157,6 +159,7 @@
{
"is_current": false,
"offer_id": "offer-c2",
"selected_amount": 0.125,
"offer": {
"provider": "aws",
"region": null,
Expand Down
Loading