From 3498bc9815e2cf7e9be22bfcf025d888cf83eb1b Mon Sep 17 00:00:00 2001 From: Sebastian Rivera Date: Mon, 21 Oct 2024 14:31:13 -0400 Subject: [PATCH] Sort JSON objects before comparing to prevent rc error --- internal/command/modules_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/command/modules_test.go b/internal/command/modules_test.go index 678895ce5f..66747f46c7 100644 --- a/internal/command/modules_test.go +++ b/internal/command/modules_test.go @@ -7,10 +7,12 @@ import ( "encoding/json" "os" "reflect" + "sort" "strings" "testing" "github.com/hashicorp/cli" + "github.com/hashicorp/terraform/internal/moduleref" ) func TestModules_noJsonFlag(t *testing.T) { @@ -130,7 +132,7 @@ func TestModules_uninstalledModules(t *testing.T) { } func compareJSONOutput(t *testing.T, got string, want string) { - var expected, actual map[string]interface{} + var expected, actual moduleref.Manifest if err := json.Unmarshal([]byte(got), &actual); err != nil { t.Fatalf("Failed to unmarshal actual JSON: %v", err) @@ -140,6 +142,13 @@ func compareJSONOutput(t *testing.T, got string, want string) { t.Fatalf("Failed to unmarshal expected JSON: %v", err) } + sort.Slice(actual.Records, func(i, j int) bool { + return actual.Records[i].Key < actual.Records[j].Key + }) + sort.Slice(expected.Records, func(i, j int) bool { + return expected.Records[i].Key < expected.Records[j].Key + }) + if !reflect.DeepEqual(expected, actual) { t.Fatalf("unexpected output, got: %s\n, want:%s\n", got, want) }