-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathagent_test.go
109 lines (100 loc) · 2.45 KB
/
agent_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"path/filepath"
"testing"
"gopkg.in/bsm/openrtb.v1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
// this is from openrtb, useful :-)
func fixture(fname string, v interface{}) error {
data, err := ioutil.ReadFile(filepath.Join("testdata", fname+".json"))
if err != nil {
return err
}
return json.Unmarshal(data, v)
}
func TestLoadAndMarshallConfig(t *testing.T) {
var agent Agent
var buffer bytes.Buffer
agents, _ := LoadAgentsFromFile("./agents.json")
agent = agents[0]
body, _ := json.Marshal(agent.Config)
var jsonDoc = `{
"account": ["hello", "world"],
"augmentations" : {
"frequency-cap-ex" : {
"config" : 42,
"filters" : {
"include" : [ "pass-frequency-cap-ex" ]
},
"required" : true
},
"random" : null
},
"bidControl" : {
"fixedBidCpmInMicros" : 0,
"type" : "RELAY"
},
"bidProbability" : 0.1,
"creatives" : [
{
"format" : "728x90",
"id" : 2,
"name" : "LeaderBoard"
},
{
"format" : "160x600",
"id" : 0,
"name" : "LeaderBoard"
},
{
"format" : "300x250",
"id" : 1,
"name" : "BigBox"
}
],
"errorFormat" : "lightweight",
"external" : false,
"externalId" : 0,
"lossFormat" : "lightweight",
"minTimeAvailableMs" : 5,
"winFormat" : "full"
}`
json.Compact(&buffer, []byte(jsonDoc))
jsonResult := (&buffer).Bytes()
if !bytes.Equal(body, jsonResult) {
t.Errorf("Expected to be equal, but it was: %s == %s", body, jsonResult)
}
}
func ExampleLoadAgentsFromFile() {
agents, err := LoadAgentsFromFile("./agents.json")
if err != nil {
log.Fatal(err)
}
fmt.Println(agents[0].Name)
// Output: my_http_config
}
var _ = Describe("Agent", func() {
var res *openrtb.Response
var req *openrtb.Request
var a Agent
BeforeEach(func() {
config := AgentConfig{Creatives: []Creative{Creative{Id: 1}}}
a = Agent{Name: "test_agent", Config: config, Price: 1.0, Period: 30000, Balance: 15000}
err := fixture("openrtb1_req", &req)
res = emptyResponseWithOneSeat(req)
Expect(err).NotTo(HaveOccurred())
Expect(req.Imp[0].Id).NotTo(BeNil())
})
It("bid should have a price", func() {
ids := externalIdsFromRequest(req)
a.DoBid(req, res, ids)
Expect(*res.Seatbid[0].Bid[0].Price).To(Equal(float32(1.0)))
})
})