From 1236c59e1830af8a382a97d79acf0a1252892757 Mon Sep 17 00:00:00 2001 From: Repinoid Date: Thu, 24 Sep 2026 10:52:36 +0300 Subject: [PATCH] =?UTF-8?q?test(provider):=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D1=8B=20=D0=BA=D0=B0=D0=BD=D0=BE=D0=BD=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20vIPConfigure=20(jsonencode-=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B0,=20=D0=BF=D1=80=D0=BE=D0=B1=D0=B5=D0=BB=D1=8B,=20[?= =?UTF-8?q?{}],=20=D0=BD=D0=B5=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=BD=D1=8B?= =?UTF-8?q?=D0=B9=20JSON)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources_core/org_ip_allocation_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/provider/internal/resources_core/org_ip_allocation_test.go b/provider/internal/resources_core/org_ip_allocation_test.go index 5dfcaf9..7e7bb23 100644 --- a/provider/internal/resources_core/org_ip_allocation_test.go +++ b/provider/internal/resources_core/org_ip_allocation_test.go @@ -51,6 +51,35 @@ func TestFormatVipConfigure_Canonical(t *testing.T) { } } +// Канонизация пользовательского ввода: terraform jsonencode сортирует ключи по алфавиту +// (count раньше name), а канон у нас — name,count. Без канонизации план ≠ state → вечный diff +// (баг воспроизведён через `terraform console`, см. NOTES/20_prompts/prompt_for_opus_review_modify_resources_2026-09-24.md). +func TestCanonicalVipConfigure_NormalizesJsonencodeForm(t *testing.T) { + raw := `[{"count":"3","name":"internet-ipv4-v1"}]` // так отдаёт jsonencode + want := `[{"name":"internet-ipv4-v1","count":"3"}]` + if got := canonicalVipConfigure(raw); got != want { + t.Fatalf("получено %q, ожидалось %q", got, want) + } +} + +func TestCanonicalVipConfigure_CompactsAndDropsEmptyElements(t *testing.T) { + raw := `[ { "count" : "4" , "name" : "internet-ipv4-v1" }, {} ]` + want := `[{"name":"internet-ipv4-v1","count":"4"}]` + if got := canonicalVipConfigure(raw); got != want { + t.Fatalf("получено %q, ожидалось %q", got, want) + } + if got := canonicalVipConfigure(`[{}]`); got != "[]" { + t.Fatalf("для [{}] ожидалось \"[]\", получено %q", got) + } +} + +func TestCanonicalVipConfigure_InvalidJSONLeftAsIs(t *testing.T) { + raw := `{not json` + if got := canonicalVipConfigure(raw); got != raw { + t.Fatalf("невалидный JSON должен остаться как есть: %q → %q", raw, got) + } +} + func TestParseVipConfigure_RoundTripIsStable(t *testing.T) { raw := `[{"name":"internet-ipv4-v1","count":"4"}]` items, err := parseVipConfigure(raw)