forked from bsm/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bidresponse_test.go
66 lines (60 loc) · 1.74 KB
/
bidresponse_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package openrtb_test
import (
"errors"
"reflect"
"testing"
. "github.com/bsm/openrtb/v3"
)
func TestBidResponse(t *testing.T) {
var subject *BidResponse
if err := fixture("bres.single", &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}
exp := &BidResponse{
ID: "BID-4-ZIMP-4b309eae-504a-4252-a8a8-4c8ceee9791a",
SeatBids: []SeatBid{
{
Bids: []Bid{
{
ID: "32a69c6ba388f110487f9d1e63f77b22d86e916b",
ImpID: "32a69c6ba388f110487f9d1e63f77b22d86e916b",
Price: 0.065445,
AdID: "529833ce55314b19e8796116",
NoticeURL: "http://ads.com/win/529833ce55314b19e8796116?won=${auction_price}",
AdMarkup: "<iframe src=\"foo.bar\"/>",
AdvDomains: []string{},
CampaignID: "529833ce55314b19e8796116",
CreativeID: "529833ce55314b19e8796116_1385706446",
Attrs: []CreativeAttribute{},
},
},
Seat: "772",
},
},
Currency: "USD",
}
if got := subject; !reflect.DeepEqual(exp, got) {
t.Errorf("expected %+v, got %+v", exp, got)
}
}
func TestBidResponse_complex(t *testing.T) {
for _, kind := range []string{"multi", "pmp", "vast"} {
var subject *BidResponse
if err := fixture("bres."+kind, &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}
if err := subject.Validate(); err != nil {
t.Fatalf("expected no error, got %v", err)
}
}
}
func TestBidResponse_Validate(t *testing.T) {
subject := &BidResponse{}
if exp, got := ErrInvalidRespNoID, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
subject = &BidResponse{ID: "RID"}
if exp, got := ErrInvalidRespNoSeatBids, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
}