Skip to content

Commit e3ff3f7

Browse files
Api updates v2 (#4)
* fix updates with emptry responses and update integration tests --------- Co-authored-by: jeremyh <[email protected]>
1 parent 937cab4 commit e3ff3f7

7 files changed

+189
-34
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: default all build clean test fmtcheck testacc sonarqube
22

3-
PKG_NAME=syntheticsclient
4-
FILES=./...
3+
PKG_NAME=syntheticsclientv2
4+
FILES=./syntheticsclientv2/...
55

66
default: test
77

syntheticsclientv2/integration_test.go

+151-6
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,28 @@ var (
2929
realm = os.Getenv("REALM")
3030
getChecksV2Body = `{"testType":"","page":1,"perPage":50,"search":"","orderBy":"id"}`
3131
inputGetChecksV2 = GetChecksV2Options{}
32-
createVariableV2Body = `{"variable":{"description":"My super awesome test variable","name":"foodz","secret":false,"value":"bar"}}`
32+
createVariableV2Body = `{"variable":{"description":"beep-var","name":"foodz","secret":false,"value":"bar"}}`
3333
inputVariableV2Data = VariableV2Input{}
34+
updateVariableV2Body = `{"variable":{"description":"My super awesome test variable22","name":"foodz","secret":false,"value":"bar"}}`
35+
updateVariableV2Data = VariableV2Input{}
3436
createLocationV2Body = `{"location":{"id":"private-data-center-go-test","label":"Data Center place", "default":false}}`
3537
inputLocationV2Data = LocationV2Input{}
3638
createHttpCheckV2Body = `{"test":{"name":"morebeeps-test","type":"http","url":"https://www.splunk.com","locationIds":["aws-us-east-1"],"frequency":10,"schedulingStrategy":"round_robin","active":true,"requestMethod":"GET","body":null,"headers":[{"name":"boop","value":"beep"}]}}`
3739
inputHttpCheckV2Data = HttpCheckV2Input{}
40+
updateHttpCheckV2Body = `{"test":{"name":"morebeeps-test","type":"http","url":"https://www.splunk.com/index/","locationIds":["aws-us-east-1"],"frequency":10,"schedulingStrategy":"round_robin","active":true,"requestMethod":"GET","body":null,"headers":[{"name":"boop","value":"beep"}]}}`
41+
updateHttpCheckV2Data = HttpCheckV2Input{}
3842
createBrowserCheckV2Body = `{"test":{"name":"browser-beep-test","transactions":[{"name":"Synthetic transaction 1","steps":[{"name":"Go to URL","type":"go_to_url","url":"https://www.splunk.com","action":"go_to_url","wait_for_nav":true},{"name":"Nexter step","type":"click_element","selectorType":"id","wait_for_nav":false,"selector":"free-splunk-click-desktop"}]}],"urlProtocol":"https://","startUrl":"www.splunk.com","locationIds":["aws-us-east-1"],"deviceId":1,"frequency":5,"schedulingStrategy":"round_robin","active":true,"advancedSettings":{"verifyCertificates":true,"authentication":{"username":"boopuser","password":"{{env.beep-var}}"},"headers":[{"name":"batman","value":"Agentoz","domain":"www.batmansagent.com"}],"cookies":[{"key":"super","value":"duper","domain":"www.batmansagent.com","path":"/boom/goes/beep"}]}}}`
3943
inputBrowserCheckV2Data = BrowserCheckV2Input{}
44+
updateBrowserCheckV2Body = `{"test":{"name":"browser-beep-test","transactions":[{"name":"Synthetic transaction 1","steps":[{"name":"Go to URL","type":"go_to_url","url":"https://www.splunk.com","action":"go_to_url","wait_for_nav":true},{"name":"Nexter step","type":"click_element","selectorType":"id","wait_for_nav":false,"selector":"free-splunk-click-desktop"}]}],"urlProtocol":"https://","startUrl":"www.splunk.com","locationIds":["aws-us-east-1"],"deviceId":1,"frequency":5,"schedulingStrategy":"round_robin","active":true,"advancedSettings":{"verifyCertificates":true,"authentication":{"username":"boopuser","password":"{{env.beep-var}}"},"headers":[{"name":"batman","value":"Agentoz","domain":"www.batmansagent.com"}],"cookies":[{"key":"super","value":"duper","domain":"www.batmansagent.com","path":"/boom/goes/beep22"}]}}}`
45+
updateBrowserCheckV2Data = BrowserCheckV2Input{}
4046
createPortCheckV2Body = `{"test":{"name":"splunk - port 443","type":"port","url":"","port":443,"protocol":"tcp","host":"www.splunk.com","locationIds":["aws-us-east-1"],"frequency":10,"schedulingStrategy":"round_robin","active":true}}`
4147
inputPortCheckV2Data = PortCheckV2Input{}
48+
updatePortCheckV2Body = `{"test":{"name":"splunk - port 448","type":"port","url":"","port":448,"protocol":"tcp","host":"www.splunk.com","locationIds":["aws-us-east-1"],"frequency":10,"schedulingStrategy":"round_robin","active":true}}`
49+
updatePortCheckV2Data = PortCheckV2Input{}
4250
createApiV2Body = `{"test":{"active":true,"deviceId":1,"frequency":5,"locationIds":["aws-us-east-1"],"name":"boop-test","schedulingStrategy":"round_robin","requests":[{"configuration":{"name":"Get-Test","requestMethod": "GET","url":"https://api.us1.signalfx.com/v2/synthetics/tests/api/489","headers":{"X-SF-TOKEN":"jinglebellsbatmanshells", "beep":"boop"},"body":null},"setup":[{"name":"Extract from response body","type":"extract_json","source":"{{response.body}}","extractor":"$.requests","variable":"custom-varz"}],"validations":[{"name":"Assert response code equals 200","type":"assert_numeric","actual":"{{response.code}}","expected":"200","comparator":"equals"}]}]}}`
4351
inputApiCheckV2Data = ApiCheckV2Input{}
52+
updateApiCheckV2Body = `{"test":{"active":true,"deviceId":1,"frequency":5,"locationIds":["aws-us-east-1"],"name":"boop-test","schedulingStrategy":"round_robin","requests":[{"configuration":{"name":"Get-Test","requestMethod": "GET","url":"https://api.us1.signalfx.com/v2/synthetics/tests/api/4892","headers":{"X-SF-TOKEN":"jinglebellsbatmanshells", "beep":"boop"},"body":null},"setup":[{"name":"Extract from response body","type":"extract_json","source":"{{response.body}}","extractor":"$.requests","variable":"custom-varz"}],"validations":[{"name":"Assert response code equals 200","type":"assert_numeric","actual":"{{response.code}}","expected":"200","comparator":"equals"}]}]}}`
53+
updateApiCheckV2Data = ApiCheckV2Input{}
4454
)
4555

4656
// You will need to fill in values for the get and delete tests
@@ -97,13 +107,40 @@ func TestLiveCreateVariableV2(t *testing.T) {
97107

98108
}
99109

110+
func TestLiveUpdateVariableV2(t *testing.T) {
111+
112+
err := json.Unmarshal([]byte(updateVariableV2Body), &updateVariableV2Data)
113+
if err != nil {
114+
t.Fatal(err)
115+
}
116+
117+
//Update your client with the token
118+
c := NewClient(token, realm)
119+
120+
fmt.Println(updateVariableV2Data)
121+
122+
// Make the request with your check settings and print result
123+
res, reqDetail, err := c.UpdateVariableV2(859, &updateVariableV2Data)
124+
if err != nil {
125+
fmt.Println(err)
126+
} else {
127+
fmt.Println(reqDetail)
128+
JsonPrint(res)
129+
}
130+
131+
if err != nil {
132+
t.Fatal(err)
133+
}
134+
135+
}
136+
100137
func TestLiveGetVariableV2(t *testing.T) {
101138

102139
//Create your client with the token
103140
c := NewClient(token, realm)
104141

105142
// Make the request with your check settings and print result
106-
res, _, err := c.GetVariableV2(246)
143+
res, _, err := c.GetVariableV2(859)
107144
if err != nil {
108145
fmt.Println(err)
109146
} else {
@@ -122,7 +159,7 @@ func TestLiveDeleteVariableV2(t *testing.T) {
122159
c := NewClient(token, realm)
123160

124161
// Make the request with your check settings and print result
125-
res, err := c.DeleteVariableV2(397)
162+
res, err := c.DeleteVariableV2(398)
126163
if err != nil {
127164
fmt.Println(err)
128165
} else {
@@ -200,6 +237,33 @@ func TestLiveGetHttpCheckV2(t *testing.T) {
200237

201238
}
202239

240+
func TestLiveUpdateHttpCheckV2(t *testing.T) {
241+
242+
err := json.Unmarshal([]byte(updateHttpCheckV2Body), &inputHttpCheckV2Data)
243+
if err != nil {
244+
t.Fatal(err)
245+
}
246+
247+
//Update your client with the token
248+
c := NewClient(token, realm)
249+
250+
fmt.Println(inputHttpCheckV2Data)
251+
252+
// Make the request with your check settings and print result
253+
res, reqDetail, err := c.UpdateHttpCheckV2(3420, &inputHttpCheckV2Data)
254+
if err != nil {
255+
fmt.Println(err)
256+
} else {
257+
fmt.Println(reqDetail)
258+
JsonPrint(res)
259+
}
260+
261+
if err != nil {
262+
t.Fatal(err)
263+
}
264+
265+
}
266+
203267
func TestLiveDeleteHttpCheckV2(t *testing.T) {
204268

205269
//Create your client with the token
@@ -265,13 +329,40 @@ func TestLiveGetBrowserCheckV2(t *testing.T) {
265329

266330
}
267331

332+
func TestLiveUpdateBrowserCheckV2(t *testing.T) {
333+
334+
err := json.Unmarshal([]byte(updateBrowserCheckV2Body), &updateBrowserCheckV2Data)
335+
if err != nil {
336+
t.Fatal(err)
337+
}
338+
339+
//Update your client with the token
340+
c := NewClient(token, realm)
341+
342+
fmt.Println(updateBrowserCheckV2Data)
343+
344+
// Make the request with your check settings and print result
345+
res, reqDetail, err := c.UpdateBrowserCheckV2(3434, &updateBrowserCheckV2Data)
346+
if err != nil {
347+
fmt.Println(err)
348+
} else {
349+
fmt.Println(reqDetail)
350+
JsonPrint(res)
351+
}
352+
353+
if err != nil {
354+
t.Fatal(err)
355+
}
356+
357+
}
358+
268359
func TestLiveDeleteBrowserCheckV2(t *testing.T) {
269360

270361
//Create your client with the token
271362
c := NewClient(token, realm)
272363

273364
// Make the request with your check settings and print result
274-
res, err := c.DeleteBrowserCheckV2(2101)
365+
res, err := c.DeleteBrowserCheckV2(3434)
275366
if err != nil {
276367
fmt.Println(err)
277368
} else {
@@ -315,7 +406,7 @@ func TestLiveGetApiCheckV2(t *testing.T) {
315406
c := NewClient(token, realm)
316407

317408
// Make the request with your check settings and print result
318-
res, _, err := c.GetApiCheckV2(489)
409+
res, _, err := c.GetApiCheckV2(3435)
319410
if err != nil {
320411
fmt.Println(err)
321412
} else {
@@ -328,13 +419,40 @@ func TestLiveGetApiCheckV2(t *testing.T) {
328419

329420
}
330421

422+
func TestLiveUpdateApiCheckV2(t *testing.T) {
423+
424+
err := json.Unmarshal([]byte(updateApiCheckV2Body), &updateApiCheckV2Data)
425+
if err != nil {
426+
t.Fatal(err)
427+
}
428+
429+
//Update your client with the token
430+
c := NewClient(token, realm)
431+
432+
fmt.Println(updateApiCheckV2Data)
433+
434+
// Make the request with your check settings and print result
435+
res, reqDetail, err := c.UpdateApiCheckV2(3435, &updateApiCheckV2Data)
436+
if err != nil {
437+
fmt.Println(err)
438+
} else {
439+
fmt.Println(reqDetail)
440+
JsonPrint(res)
441+
}
442+
443+
if err != nil {
444+
t.Fatal(err)
445+
}
446+
447+
}
448+
331449
func TestLiveDeleteApiCheckV2(t *testing.T) {
332450

333451
//Create your client with the token
334452
c := NewClient(token, realm)
335453

336454
// Make the request with your check settings and print result
337-
res, err := c.DeleteApiCheckV2(3007)
455+
res, err := c.DeleteApiCheckV2(3435)
338456
if err != nil {
339457
fmt.Println(err)
340458
} else {
@@ -393,6 +511,33 @@ func TestLiveGetPortCheckV2(t *testing.T) {
393511

394512
}
395513

514+
func TestLiveUpdatePortCheckV2(t *testing.T) {
515+
516+
err := json.Unmarshal([]byte(updatePortCheckV2Body), &updatePortCheckV2Data)
517+
if err != nil {
518+
t.Fatal(err)
519+
}
520+
521+
//Update your client with the token
522+
c := NewClient(token, realm)
523+
524+
fmt.Println(updatePortCheckV2Data)
525+
526+
// Make the request with your check settings and print result
527+
res, reqDetail, err := c.UpdatePortCheckV2(3436, &updatePortCheckV2Data)
528+
if err != nil {
529+
fmt.Println(err)
530+
} else {
531+
fmt.Println(reqDetail)
532+
JsonPrint(res)
533+
}
534+
535+
if err != nil {
536+
t.Fatal(err)
537+
}
538+
539+
}
540+
396541
func TestLiveDeletePortCheckV2(t *testing.T) {
397542

398543
//Create your client with the token

syntheticsclientv2/update_apicheckv2.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222

2323
func parseUpdateApiCheckV2Response(response string) (*ApiCheckV2Response, error) {
2424
var updateApiCheckV2 ApiCheckV2Response
25-
err := json.Unmarshal([]byte(response), &updateApiCheckV2)
26-
if err != nil {
27-
return nil, err
25+
if response != "" {
26+
err := json.Unmarshal([]byte(response), &updateApiCheckV2)
27+
if err != nil {
28+
return nil, err
29+
}
30+
return &updateApiCheckV2, err
2831
}
29-
30-
return &updateApiCheckV2, err
32+
return &updateApiCheckV2, nil
3133
}
3234

3335
func (c Client) UpdateApiCheckV2(id int, ApiCheckV2Details *ApiCheckV2Input) (*ApiCheckV2Response, *RequestDetails, error) {

syntheticsclientv2/update_browsercheckv2.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222

2323
func parseUpdateBrowserCheckV2Response(response string) (*BrowserCheckV2Response, error) {
2424
var updateBrowserCheckV2 BrowserCheckV2Response
25-
err := json.Unmarshal([]byte(response), &updateBrowserCheckV2)
26-
if err != nil {
27-
return nil, err
25+
if response != "" {
26+
err := json.Unmarshal([]byte(response), &updateBrowserCheckV2)
27+
if err != nil {
28+
return nil, err
29+
}
30+
return &updateBrowserCheckV2, err
2831
}
29-
30-
return &updateBrowserCheckV2, err
32+
return &updateBrowserCheckV2, nil
3133
}
3234

3335
func (c Client) UpdateBrowserCheckV2(id int, BrowserCheckV2Details *BrowserCheckV2Input) (*BrowserCheckV2Response, *RequestDetails, error) {

syntheticsclientv2/update_httpcheckv2.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222

2323
func parseUpdateHttpCheckV2Response(response string) (*HttpCheckV2Response, error) {
2424
var updateHttpCheckV2 HttpCheckV2Response
25-
err := json.Unmarshal([]byte(response), &updateHttpCheckV2)
26-
if err != nil {
27-
return nil, err
25+
if response != "" {
26+
err := json.Unmarshal([]byte(response), &updateHttpCheckV2)
27+
if err != nil {
28+
return nil, err
29+
}
30+
return &updateHttpCheckV2, err
2831
}
29-
30-
return &updateHttpCheckV2, err
32+
return &updateHttpCheckV2, nil
3133
}
3234

3335
func (c Client) UpdateHttpCheckV2(id int, HttpCheckV2Details *HttpCheckV2Input) (*HttpCheckV2Response, *RequestDetails, error) {

syntheticsclientv2/update_portcheckv2.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ import (
2222

2323
func parseUpdatePortCheckV2Response(response string) (*PortCheckV2Response, error) {
2424
var updatePortCheckV2 PortCheckV2Response
25-
err := json.Unmarshal([]byte(response), &updatePortCheckV2)
26-
if err != nil {
27-
return nil, err
25+
if response != "" {
26+
err := json.Unmarshal([]byte(response), &updatePortCheckV2)
27+
if err != nil {
28+
return nil, err
29+
}
30+
return &updatePortCheckV2, err
2831
}
29-
30-
return &updatePortCheckV2, err
32+
return &updatePortCheckV2, nil
3133
}
3234

3335
func (c Client) UpdatePortCheckV2(id int, PortCheckV2Details *PortCheckV2Input) (*PortCheckV2Response, *RequestDetails, error) {

syntheticsclientv2/update_variablev2.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import (
2121
)
2222

2323
func parseUpdateVariableV2Response(response string) (*VariableV2Response, error) {
24-
var updateVariableV2 VariableV2Response
25-
err := json.Unmarshal([]byte(response), &updateVariableV2)
26-
if err != nil {
27-
return nil, err
24+
var updateVariableCheckV2 VariableV2Response
25+
if response != "" {
26+
err := json.Unmarshal([]byte(response), &updateVariableCheckV2)
27+
if err != nil {
28+
return nil, err
29+
}
30+
return &updateVariableCheckV2, err
2831
}
29-
30-
return &updateVariableV2, err
32+
return &updateVariableCheckV2, nil
3133
}
3234

3335
func (c Client) UpdateVariableV2(id int, VariableV2Details *VariableV2Input) (*VariableV2Response, *RequestDetails, error) {

0 commit comments

Comments
 (0)