/
adapter_test_util.go
70 lines (60 loc) · 1.86 KB
/
adapter_test_util.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
package adapterstest
import (
"fmt"
"net/http/httptest"
"strings"
"testing"
"net/http"
"github.com/mxmCherry/openrtb/v15/openrtb2"
)
// OrtbMockService Represents a scaffolded OpenRTB service.
type OrtbMockService struct {
Server *httptest.Server
LastBidRequest *openrtb2.BidRequest
LastHttpRequest *http.Request
}
// BidOnTags Produces a map of TagIds, based on a comma separated strings. The map
// contains the list of tags to bid on.
func BidOnTags(tags string) map[string]bool {
values := strings.Split(tags, ",")
set := make(map[string]bool)
for _, tag := range values {
set[tag] = true
}
return set
}
// SampleBid Produces a sample bid based on params given.
func SampleBid(width *int64, height *int64, impId string, index int) openrtb2.Bid {
return openrtb2.Bid{
ID: "Bid-123",
ImpID: fmt.Sprintf("div-adunit-%d", index),
Price: 2.1,
AdM: "<div>This is an Ad</div>",
CrID: "Cr-234",
W: *width,
H: *height,
}
}
// VerifyStringValue Helper function to assert string equals.
func VerifyStringValue(value string, expected string, t *testing.T) {
if value != expected {
t.Fatalf(fmt.Sprintf("%s expected, got %s", expected, value))
}
}
// VerifyIntValue Helper function to assert Int equals.
func VerifyIntValue(value int, expected int, t *testing.T) {
if value != expected {
t.Fatalf(fmt.Sprintf("%d expected, got %d", expected, value))
}
}
// VerifyBoolValue Helper function to assert bool equals.
func VerifyBoolValue(value bool, expected bool, t *testing.T) {
if value != expected {
t.Fatalf(fmt.Sprintf("%v expected, got %v", expected, value))
}
}
// VerifyBannerSize helper function to assert banner size
func VerifyBannerSize(banner *openrtb2.Banner, expectedWidth int, expectedHeight int, t *testing.T) {
VerifyIntValue(int(*(banner.W)), expectedWidth, t)
VerifyIntValue(int(*(banner.H)), expectedHeight, t)
}