Example #1
0
// verifyMacroSubs runs openrtb.MacroSubs and checks if the output is the expected string.
func verifyMacroSubs(t *testing.T, input string, bidRes *openrtb.BidResponse, expectedOutput string) {
	result, err := openrtb.MacroSubs(input, bidRes)
	if err != nil {
		t.Fatal("MacroSubs should complete successfully")
	}

	if result != expectedOutput {
		t.Errorf("Got the wrong result.\nExpected: %s\nActual: %s", expectedOutput, result)
	}
}
Example #2
0
// TestMacroSubsErrCases checks cases where MacroSubs might have an error.
// MacroSubs expects that the BidResponse has exactly one seat with exactly one bid.
func TestMacroSubsErrCases(t *testing.T) {
	var bid1 = openrtb.Bid{Id: "bid1"}
	var bid2 = openrtb.Bid{Id: "bid2"}
	var seatbidWith2Bids = openrtb.SeatBid{
		Seat: "seatbidWith2Bids",
		Bids: []*openrtb.Bid{&bid1, &bid2},
	}
	var bidResWith2Bids = &openrtb.BidResponse{
		Id:       "bidResWith2Bids",
		SeatBids: []*openrtb.SeatBid{&seatbidWith2Bids},
	}

	var seatbid1 = openrtb.SeatBid{
		Seat: "seatbid1",
		Bids: []*openrtb.Bid{&bid1},
	}
	var seatbid2 = openrtb.SeatBid{
		Seat: "seatbid2",
		Bids: []*openrtb.Bid{&bid2},
	}
	var bidResWith2Seatbids = &openrtb.BidResponse{
		Id:       "bidResWith2Seatbids",
		SeatBids: []*openrtb.SeatBid{&seatbid1, &seatbid2},
	}

	t.Log("Testing bidResWith2Bids")
	result, err := openrtb.MacroSubs("${AUCTION_ID}${AUCTION_BID_ID}", bidResWith2Bids)
	if err != openrtb.ErrIncorrectBidCount {
		t.Error("bidResWith2Seatbids should give ErrIncorrectBidCount")
	}
	if result != "" {
		t.Error("MacroSubs should empty string when there is an error")
	}

	t.Log("Testing bidResWith2Seatbids")
	result, err = openrtb.MacroSubs("${AUCTION_ID}${AUCTION_SEAT_ID}", bidResWith2Seatbids)
	if err != openrtb.ErrIncorrectSeatCount {
		t.Error("bidResWith2Seatbids should give ErrIncorrectBidCount")
	}
	if result != "" {
		t.Error("MacroSubs should empty string when there is an error")
	}
}