Skip to content

Commit

Permalink
This will fail validation because the test supplemental/banner-and-ad…
Browse files Browse the repository at this point in the history
…m-video-unexpected-204-response-on-banner.json is an invalid test and gets caught as such in test_json.go diffBidLists().
  • Loading branch information
jim naumann committed Mar 16, 2021
1 parent f3e55a5 commit 30d9eb8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
48 changes: 25 additions & 23 deletions adapters/adapterstest/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,28 +126,6 @@ func runSpec(t *testing.T, filename string, spec *testSpec, bidder adapters.Bidd
diffBidLists(t, filename, bidResponses[i], spec.BidResponses[i].Bids)
}
}
func diffBidLists(t *testing.T, filename string, response *adapters.BidderResponse, expected []expectedBid) {
t.Helper()

// We either received a nil response unexpectedly, or a non-nil response expecting nil
if (response == nil || len(response.Bids) == 0) != (len(expected) == 0) {
return
}

// Received an expected nil response, so give diffBids something to work with
if response == nil {
response = new(adapters.BidderResponse)
}

actual := response.Bids

if len(actual) != len(expected) {
t.Fatalf("%s: MakeBids returned wrong bid count. Expected %d, got %d", filename, len(expected), len(actual))
}
for i := 0; i < len(actual); i++ {
diffBids(t, fmt.Sprintf("%s: typedBid[%d]", filename, i), actual[i], &(expected[i]))
}
}

type testSpec struct {
BidRequest openrtb.BidRequest `json:"mockBidRequest"`
Expand Down Expand Up @@ -249,7 +227,31 @@ func diffErrorLists(t *testing.T, description string, actual []error, expected [
}
}

// ORIGINAL LOCATION
func diffBidLists(t *testing.T, filename string, response *adapters.BidderResponse, expected []expectedBid) {
t.Helper()

if (response == nil || len(response.Bids) == 0) && (len(expected) != 0) {
if len(expected) == 0 {
t.Fatalf("%s: Makebids expected a nil response, but got a non-nil response", filename)
}

t.Fatalf("%s: MakeBids received unexpected nil or empty response", filename)
}

// Expected nil response - give diffBids something to work with.
if response == nil {
response = new(adapters.BidderResponse)
}

actual := response.Bids

if len(actual) != len(expected) {
t.Fatalf("%s: MakeBids returned wrong bid count. Expected %d, got %d", filename, len(expected), len(actual))
}
for i := 0; i < len(actual); i++ {
diffBids(t, fmt.Sprintf("%s: typedBid[%d]", filename, i), actual[i], &(expected[i]))
}
}

// diffHttpRequests compares the actual HTTP request data to the expected one.
// It assumes that the request bodies are JSON
Expand Down
4 changes: 2 additions & 2 deletions adapters/beachfront/beachfront.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, []
}

bfReqs[i].Request.Imp = nil
bfReqs[i].Request.Imp = make([]openrtb.Imp, 1, 1)
bfReqs[i].Request.Imp = make([]openrtb.Imp, 1)
bfReqs[i].Request.Imp[0] = imp

}
Expand All @@ -483,6 +483,7 @@ func getVideoRequests(request *openrtb.BidRequest) ([]beachfrontVideoRequest, []
}

func (a *BeachfrontAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
bidResponse := adapters.NewBidderResponseWithBidsCapacity(BidCapacity)

if response.StatusCode == http.StatusNoContent {
return nil, nil
Expand Down Expand Up @@ -521,7 +522,6 @@ func (a *BeachfrontAdapter) MakeBids(internalRequest *openrtb.BidRequest, extern
}

var dur beachfrontVideoBidExtension
bidResponse := adapters.NewBidderResponseWithBidsCapacity(BidCapacity)
for i := 0; i < len(bids); i++ {

// If we unmarshal without an error, this is an AdM video
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
],

"expectedBidResponses": [
{"bids":[]},
{
"bids": [
{
Expand Down

0 comments on commit 30d9eb8

Please sign in to comment.