Skip to content

Commit 7fec5df

Browse files
Fixup #669: only serialize the map once (#671) (#672)
Co-authored-by: Laurent Saint-Félix <[email protected]>
1 parent 967bf82 commit 7fec5df

File tree

1 file changed

+4
-3
lines changed
  • internal/build/cmd/generate/commands/gentests

1 file changed

+4
-3
lines changed

internal/build/cmd/generate/commands/gentests/model.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,8 @@ default:
695695
// We cannot reliably serialize to json and compare the json outputs: YAML responses are parsed as
696696
// a map[interface{}]interface{} that encoding/json fails to marshall
697697
// See https://play.golang.org/p/jhcXwg5dIrn
698-
expectedPayload := flattenPayload(val)
698+
expectedOutput := flattenPayload(val)
699+
expectedPayload := fmt.Sprintf("%#v", expectedOutput)
699700

700701
expectedPayload = strings.ReplaceAll(expectedPayload, "map[interface {}]interface {}", "map[string]interface {}")
701702
output = ` actual = fmt.Sprintf("%v",` + escape(subject) + `)
@@ -940,7 +941,7 @@ func skipVersion(minmax string) bool {
940941
}
941942

942943
// flattenPayload serializes the expected payload as a map tree to compare within tests.
943-
func flattenPayload(val interface{}) string {
944+
func flattenPayload(val interface{}) map[string]interface{} {
944945
expectedOutput := make(map[string]interface{})
945946
if cast, ok := val.(map[interface{}]interface{}); ok {
946947
for k, v := range cast {
@@ -952,5 +953,5 @@ func flattenPayload(val interface{}) string {
952953
} else {
953954
expectedOutput = val.(map[string]interface{})
954955
}
955-
return fmt.Sprintf("%#v", expectedOutput)
956+
return expectedOutput
956957
}

0 commit comments

Comments
 (0)