-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseatbid_test.go
95 lines (89 loc) · 1.89 KB
/
seatbid_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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package gortb
import (
"encoding/json"
"testing"
)
func TestSeatBid(t *testing.T) {
tests := []struct {
name string
seatbid *SeatBid
wantErr error
}{
{
name: "valid seatbid",
seatbid: &SeatBid{
Bids: []Bid{
{
ID: "test-bid-1",
ImpID: "test-imp-1",
Price: 1.23,
AdID: "test-ad-1",
NURL: "http://test.com/nurl",
BURL: "http://test.com/burl",
LURL: "http://test.com/lurl",
AdM: "<creative>test</creative>",
CID: "test-campaign-1",
},
},
Seat: "test-seat",
Group: 0,
},
wantErr: nil,
},
{
name: "empty bids",
seatbid: &SeatBid{
Bids: []Bid{},
Seat: "test-seat",
Group: 0,
},
wantErr: ErrInvalidBids,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.seatbid.Validate()
if tt.wantErr != nil {
if err == nil {
t.Errorf("SeatBid.Validate() error = nil, wantErr = %v", tt.wantErr)
return
}
if err.Error() != tt.wantErr.Error() {
t.Errorf("SeatBid.Validate() error = %v, wantErr = %v", err, tt.wantErr)
}
return
}
if err != nil {
t.Errorf("SeatBid.Validate() error = %v, wantErr = nil", err)
}
})
}
}
func TestSeatBidWithJSON(t *testing.T) {
jsonData := `{
"bid": [{
"id": "test-bid-1",
"impid": "test-imp-1",
"price": 1.23,
"adid": "test-ad-1",
"nurl": "http://test.com/nurl",
"burl": "http://test.com/burl",
"lurl": "http://test.com/lurl",
"adm": "<creative>test</creative>",
"cid": "test-campaign-1",
"crid": "test-creative-1",
"apikey": "test-api-key"
}],
"seat": "test-seat",
"group": 0
}`
var seatbid SeatBid
err := json.Unmarshal([]byte(jsonData), &seatbid)
if err != nil {
t.Fatalf("Failed to unmarshal JSON: %v", err)
}
err = seatbid.Validate()
if err != nil {
t.Errorf("SeatBid.Validate() error = %v, wantErr = nil", err)
}
}