Skip to content

Commit

Permalink
Update adapter json test framework to validate BidVideo (#3835)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurb9 authored Sep 12, 2024
1 parent 6cbedf0 commit 7613ff5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
19 changes: 16 additions & 3 deletions adapters/adapterstest/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ type expectedBidResponse struct {
}

type expectedBid struct {
Bid json.RawMessage `json:"bid"`
Type string `json:"type"`
Seat string `json:"seat"`
Bid json.RawMessage `json:"bid"`
Type string `json:"type"`
Seat string `json:"seat"`
Video json.RawMessage `json:"video,omitempty"`
}

// ---------------------------------------
Expand Down Expand Up @@ -342,6 +343,9 @@ func diffBids(t *testing.T, description string, actual *adapters.TypedBid, expec
assert.Equal(t, string(expected.Seat), string(actual.Seat), fmt.Sprintf(`%s.seat "%s" does not match expected "%s."`, description, string(actual.Seat), string(expected.Seat)))
assert.Equal(t, string(expected.Type), string(actual.BidType), fmt.Sprintf(`%s.type "%s" does not match expected "%s."`, description, string(actual.BidType), string(expected.Type)))
assert.NoError(t, diffOrtbBids(fmt.Sprintf("%s.bid", description), actual.Bid, expected.Bid))
if expected.Video != nil {
assert.NoError(t, diffBidVideo(fmt.Sprintf("%s.video", description), actual.BidVideo, expected.Video))
}
}

// diffOrtbBids compares the actual Bid made by the adapter to the expectation from the JSON file.
Expand All @@ -358,6 +362,15 @@ func diffOrtbBids(description string, actual *openrtb2.Bid, expected json.RawMes
return diffJson(description, actualJson, expected)
}

func diffBidVideo(description string, actual *openrtb_ext.ExtBidPrebidVideo, expected json.RawMessage) error {
actualJson, err := json.Marshal(actual)
if err != nil {
return fmt.Errorf("%s failed to marshal actual Bid Video into JSON. %v", description, err)
}

return diffJson(description, actualJson, []byte(expected))
}

// diffJson compares two JSON byte arrays for structural equality. It will produce an error if either
// byte array is not actually JSON.
func diffJson(description string, actual []byte, expected []byte) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@
},
"type": "video",
"video" : {
"duration" : 10
"duration" : 10,
"primary_category": ""
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion adapters/pubmatic/pubmatictest/exemplary/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@
},
"type": "video",
"video" :{
"duration" : 5
"duration" : 5,
"primary_category": ""
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion adapters/yeahmobi/yeahmobitest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
},
"type": "video",
"video": {
"duration": 300
"duration": 300,
"primary_category": ""
}
}
]
Expand Down

0 comments on commit 7613ff5

Please sign in to comment.