@@ -22,11 +22,77 @@ import (
22
22
"net/http"
23
23
"reflect"
24
24
"testing"
25
+ "time"
25
26
)
26
27
27
28
var (
28
- getBrowserCheckV2Body = `{"test":{"automaticRetries": 1, "customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "active":true,"advancedSettings":{"authentication":{"password":"password123","username":"myuser"},"cookies":[{"key":"qux","value":"qux","domain":"splunk.com","path":"/qux"}],"headers":[{"name":"Accept","value":"application/json","domain":"splunk.com"}],"verifyCertificates":true},"createdAt":"2022-09-14T14:35:37.801Z","device":{"id":1,"label":"iPhone","networkConnection":{"description":"Mobile LTE","downloadBandwidth":12000,"latency":70,"packetLoss":0,"uploadBandwidth":12000},"viewportHeight":844,"viewportWidth":375},"frequency":5,"id":1,"locationIds":["na-us-virginia"],"name":"My Test","schedulingStrategy":"round_robin","transactions":[{"name":"Example transaction","steps":[{"name":"element step","selector":".main","selectorType":"css","type":"click_element","waitForNav":true,"waitForNavTimeout":2000}]}],"type":"browser","updatedAt":"2022-09-14T14:35:38.099Z","lastRunAt":"2024-03-07T00:47:43.741Z","lastRunStatus":"success","createdBy":"abc1234","updatedBy":"abc1234"}}`
29
+ getBrowserCheckV2Body = `{"test":{"automaticRetries": 1, "customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "active":true,"advancedSettings":{"authentication":{"password":"password123","username":"myuser"},"cookies":[{"key":"qux","value":"qux","domain":"splunk.com","path":"/qux"}],"headers":[{"name":"Accept","value":"application/json","domain":"splunk.com"}],"verifyCertificates":true},"createdAt":"2022-09-14T14:35:37.801Z","device":{"id":1,"label":"iPhone","networkConnection":{"description":"Mobile LTE","downloadBandwidth":12000,"latency":70,"packetLoss":0,"uploadBandwidth":12000},"viewportHeight":844,"viewportWidth":375},"frequency":5,"id":1,"locationIds":["na-us-virginia"],"name":"My Test","schedulingStrategy":"round_robin","transactions":[{"name":"Example transaction","steps":[{"name":"element step","selector":".main","selectorType":"css","type":"click_element","waitForNav":true,"waitForNavTimeout":2000,"waitForNavTimeoutDefault":true,"maxWaitTime":10000,"maxWaitTimeDefault":true}]}],"type":"browser","updatedAt":"2022-09-14T14:35:38.099Z","lastRunAt":"2024-03-07T00:47:43.741Z","lastRunStatus":"success","createdBy":"abc1234","updatedBy":"abc1234"}}`
29
30
inputGetBrowserCheckV2 = verifyBrowserCheckV2Input (string (getBrowserCheckV2Body ))
31
+ expectedBrowserCheckV2 = BrowserCheckV2Response {
32
+ Test : BrowserCheckV2ResponseTest {
33
+ Automaticretries : 1 ,
34
+ Customproperties : []CustomProperties {
35
+ {Key : "Test_Key" , Value : "Test Custom Properties" },
36
+ },
37
+ Active : true ,
38
+ Advancedsettings : Advancedsettings {
39
+ Authentication : & Authentication {
40
+ Password : "password123" ,
41
+ Username : "myuser" ,
42
+ },
43
+ Cookiesv2 : []Cookiesv2 {
44
+ {Key : "qux" , Value : "qux" , Domain : "splunk.com" , Path : "/qux" },
45
+ },
46
+ BrowserHeaders : []BrowserHeaders {
47
+ {Name : "Accept" , Value : "application/json" , Domain : "splunk.com" },
48
+ },
49
+ Verifycertificates : true ,
50
+ },
51
+ Createdat : time .Date (2022 , 9 , 14 , 14 , 35 , 37 , 801000000 , time .UTC ),
52
+ Device : Device {
53
+ ID : 1 ,
54
+ Label : "iPhone" ,
55
+ Networkconnection : Networkconnection {
56
+ Description : "Mobile LTE" ,
57
+ Downloadbandwidth : 12000 ,
58
+ Latency : 70 ,
59
+ Packetloss : 0 ,
60
+ Uploadbandwidth : 12000 ,
61
+ },
62
+ Viewportheight : 844 ,
63
+ Viewportwidth : 375 ,
64
+ },
65
+ Frequency : 5 ,
66
+ ID : 1 ,
67
+ Locationids : []string {"na-us-virginia" },
68
+ Name : "My Test" ,
69
+ Schedulingstrategy : "round_robin" ,
70
+ Transactions : []Transactions {
71
+ {
72
+ Name : "Example transaction" ,
73
+ StepsV2 : []StepsV2 {
74
+ {
75
+ Name : "element step" ,
76
+ Selector : ".main" ,
77
+ SelectorType : "css" ,
78
+ Type : "click_element" ,
79
+ WaitForNav : true ,
80
+ WaitForNavTimeout : 2000 ,
81
+ WaitForNavTimeoutDefault : true ,
82
+ MaxWaitTime : 10000 ,
83
+ MaxWaitTimeDefault : true ,
84
+ },
85
+ },
86
+ },
87
+ },
88
+ Type : "browser" ,
89
+ Updatedat : time .Date (2022 , 9 , 14 , 14 , 35 , 38 , 99000000 , time .UTC ),
90
+ Lastrunat : time .Date (2024 , 3 , 7 , 0 , 47 , 43 , 741000000 , time .UTC ),
91
+ Lastrunstatus : "success" ,
92
+ Createdby : "abc1234" ,
93
+ Updatedby : "abc1234" ,
94
+ },
95
+ }
30
96
)
31
97
32
98
func TestGetBrowserCheckV2 (t * testing.T ) {
@@ -46,6 +112,11 @@ func TestGetBrowserCheckV2(t *testing.T) {
46
112
if err != nil {
47
113
t .Fatal (err )
48
114
}
115
+ // verify the json is unmarshalled correctly
116
+ if ! reflect .DeepEqual (* inputGetBrowserCheckV2 , expectedBrowserCheckV2 ) {
117
+ t .Errorf ("returned \n \n %#v want \n \n %#v" , * inputGetBrowserCheckV2 , expectedBrowserCheckV2 )
118
+ }
119
+
49
120
if ! reflect .DeepEqual (resp .Test .ID , inputGetBrowserCheckV2 .Test .ID ) {
50
121
t .Errorf ("returned \n \n %#v want \n \n %#v" , resp .Test .ID , inputGetBrowserCheckV2 .Test .ID )
51
122
}
@@ -89,6 +160,11 @@ func TestGetBrowserCheckV2(t *testing.T) {
89
160
if ! reflect .DeepEqual (resp .Test .Customproperties , inputGetBrowserCheckV2 .Test .Customproperties ) {
90
161
t .Errorf ("returned \n \n %#v want \n \n %#v" , resp .Test .Customproperties , inputGetBrowserCheckV2 .Test .Customproperties )
91
162
}
163
+
164
+ // verify the whole response
165
+ if ! reflect .DeepEqual (* resp , expectedBrowserCheckV2 ) {
166
+ t .Errorf ("returned \n \n %#v want \n \n %#v" , * resp , expectedBrowserCheckV2 )
167
+ }
92
168
}
93
169
94
170
func verifyBrowserCheckV2Input (stringInput string ) * BrowserCheckV2Response {
@@ -97,5 +173,9 @@ func verifyBrowserCheckV2Input(stringInput string) *BrowserCheckV2Response {
97
173
if err != nil {
98
174
panic (err )
99
175
}
176
+ empty := BrowserCheckV2Response {}
177
+ if reflect .DeepEqual (empty , * check ) {
178
+ panic ("Unmarshal failed, empty struct returned" )
179
+ }
100
180
return check
101
181
}
0 commit comments