Skip to content

Commit 62632a3

Browse files
Loosen requirements on the data payload of CloudEvents. (#30)
When a legacy event is converted to a CloudEvent, we know that we want a certain JSON payload, but we shouldn't require that payload to be formatted exactly the same as the JSON payload in our golden files. Instead, we unmarshal both the actual and expected values into maps, and we check that those maps are equal.
1 parent 8e1731d commit 62632a3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

events/validators.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ func validateCloudEvent(name string, gotBytes, wantBytes []byte) *ValidationInfo
224224
},
225225
{
226226
name: "data",
227-
gotValue: string(got.Data()),
228-
wantValue: string(want.Data()),
227+
gotValue: unmarshalMap(got.Data(), vi),
228+
wantValue: unmarshalMap(want.Data(), vi),
229229
},
230230
}
231231
for _, field := range fields {
@@ -236,3 +236,10 @@ func validateCloudEvent(name string, gotBytes, wantBytes []byte) *ValidationInfo
236236

237237
return vi
238238
}
239+
240+
func unmarshalMap(data []byte, vi *ValidationInfo) (dataMap map[string]interface{}) {
241+
if err := json.Unmarshal(data, &dataMap); err != nil {
242+
vi.Errs = append(vi.Errs, fmt.Errorf("could not parse CloudEvent data as map: %v", err))
243+
}
244+
return
245+
}

0 commit comments

Comments
 (0)