Skip to content

Commit ef1b21b

Browse files
SYN-3798: add new filters for new test filters (#19)
* SYN-3798: add new filters for new test filters * lint * handle nil * update output of getChecksV2Output
1 parent 749add8 commit ef1b21b

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

syntheticsclientv2/common_models.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,18 @@ type Tests []struct {
155155
}
156156

157157
type GetChecksV2Options struct {
158-
TestType string `json:"testType"`
159-
PerPage int `json:"perPage"`
160-
Page int `json:"page"`
161-
Search string `json:"search"`
162-
OrderBy string `json:"orderBy"`
158+
TestType string `json:"testType"`
159+
PerPage int `json:"perPage"`
160+
Page int `json:"page"`
161+
Search string `json:"search"`
162+
OrderBy string `json:"orderBy"`
163+
Active *bool `json:"active"`
164+
CustomProperties []CustomProperties `json:"customProperties"`
165+
Frequencies []int `json:"frequencies"`
166+
LastRunStatus []string `json:"lastRunStatus"`
167+
LocationIds []string `json:"locationIds"`
168+
SchedulingStrategy string `json:"schedulingStrategy"`
169+
TestTypes []string `json:"testTypes"`
163170
}
164171

165172
type Errors []struct {

syntheticsclientv2/get_checksv2.go

+52-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"bytes"
1919
"encoding/json"
2020
"fmt"
21+
"strings"
22+
"strconv"
2123
)
2224

2325
func parseChecksV2Response(response string) (*ChecksV2Response, error) {
@@ -46,11 +48,27 @@ func (c Client) GetChecksV2(params *GetChecksV2Options) (*ChecksV2Response, *Req
4648
if params.PerPage == 0 {
4749
params.PerPage = int(50)
4850
}
51+
if params.SchedulingStrategy == "" {
52+
params.SchedulingStrategy = ""
53+
}
4954

5055
// Make the request
5156
details, err := c.makePublicAPICall(
5257
"GET",
53-
fmt.Sprintf("/tests?testType=%s&page=%d&perPage=%d&orderBy=%s&search=%s", params.TestType, params.Page, params.PerPage, params.OrderBy, params.Search),
58+
fmt.Sprintf("/tests?testType=%s&page=%d&perPage=%d&orderBy=%s&search=%s%s&schedulingStrategy=%s%s%s%s%s%s",
59+
params.TestType,
60+
params.Page,
61+
params.PerPage,
62+
params.OrderBy,
63+
params.Search,
64+
activeQueryParam(params.Active),
65+
params.SchedulingStrategy,
66+
customPropsQueryParam(params.CustomProperties),
67+
stringsQueryParam(params.LastRunStatus, "&lastRunStatus[]="),
68+
stringsQueryParam(params.LocationIds, "&locationIds[]="),
69+
stringsQueryParam(params.TestTypes, "&testTypes[]="),
70+
integersQueryParam(params.Frequencies, "&frequencies[]="),
71+
),
5472
bytes.NewBufferString("{}"),
5573
nil)
5674

@@ -66,3 +84,36 @@ func (c Client) GetChecksV2(params *GetChecksV2Options) (*ChecksV2Response, *Req
6684

6785
return check, details, nil
6886
}
87+
88+
func activeQueryParam(param *bool) (string) {
89+
if param != nil {
90+
boolString := strconv.FormatBool(*param)
91+
return fmt.Sprintf("&active=%s", boolString)
92+
}
93+
return ""
94+
}
95+
96+
func customPropsQueryParam(params []CustomProperties) (string) {
97+
if len(params) == 0 {
98+
return ""
99+
}
100+
var result string
101+
for _, customProp := range params {
102+
result += "&customProperties[]=" + customProp.Key + ":" + customProp.Value
103+
}
104+
return result
105+
}
106+
107+
func integersQueryParam(params []int, queryParamName string) (string) {
108+
if len(params) == 0 {
109+
return ""
110+
}
111+
return queryParamName + strings.Trim(strings.Replace(fmt.Sprint(params), " ", queryParamName, -1), "[]")
112+
}
113+
114+
func stringsQueryParam(params []string, queryParamName string) (string) {
115+
if len(params) == 0 {
116+
return ""
117+
}
118+
return queryParamName + strings.Join(params, queryParamName)
119+
}

syntheticsclientv2/get_checksv2_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
var (
2828
getChecksV2Body = `{"testType":"","page":1,"perPage":50,"search":"","orderBy":"id"}`
2929
inputGetChecksV2 = verifyChecksV2Input(string(getChecksV2Body))
30-
getChecksV2Output = `{"tests":[{"id":482,"name":"Test of Splunk.com","active":true,"frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-08-15T16:05:25.815Z","updated_at":"2022-09-29T19:13:13.853Z","location_ids":["aws-us-east-1"],"type":"browser"},{"id":489,"name":"Appinspect login API","active":true,"frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-08-16T15:47:43.730Z","updated_at":"2022-08-16T15:47:43.741Z","location_ids":["aws-us-east-1"],"type":"api"},{"id":490,"name":"Arch Linux Packages","active":true,"frequency":10,"scheduling_strategy":"round_robin","created_at":"2022-08-16T16:48:42.119Z","updated_at":"2022-08-16T16:48:42.131Z","location_ids":["aws-us-east-1"],"type":"http"},{"id":492,"name":"Test of Splunkbase","active":true,"frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-08-16T19:35:54.014Z","updated_at":"2022-09-29T19:13:13.907Z","location_ids":["aws-us-east-1"],"type":"browser"},{"id":493,"name":"Brewery API","active":true,"frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-08-16T19:44:15.626Z","updated_at":"2022-08-16T19:44:15.635Z","location_ids":["aws-us-east-1"],"type":"api"},{"id":495,"name":"Multi-step test of legacy Splunkbase","active":true,"frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-08-17T01:24:44.579Z","updated_at":"2022-09-29T19:13:13.203Z","location_ids":["aws-us-east-1"],"type":"browser"},{"id":496,"name":"Multi-step Test of new Splunkbase","active":true,"frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-08-17T01:33:27.771Z","updated_at":"2022-09-29T19:13:13.997Z","location_ids":["aws-us-east-1"],"type":"browser"},{"id":935,"name":"This test does test stuff","active":true,"frequency":30,"scheduling_strategy":"round_robin","created_at":"2022-10-26T14:48:36.026Z","updated_at":"2022-10-26T14:48:36.037Z","location_ids":["aws-us-east-1"],"type":"api"},{"id":1116,"name":"boop-test","active":true,"frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-11-16T19:18:59.603Z","updated_at":"2022-11-16T19:20:58.911Z","location_ids":["aws-us-east-1","aws-ap-northeast-1"],"type":"api"},{"id":1128,"name":"boopbeep","active":true,"frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-11-17T14:19:49.564Z","updated_at":"2022-11-17T14:19:49.571Z","location_ids":["aws-us-east-1"],"type":"browser"}],"page":1,"per_page":50,"next_page_link":null,"total_count":10}`
30+
getChecksV2Output = `{"tests":[{"id":482,"name":"Test of Splunk.com","active":true,"frequency":5,"schedulingStrategy":"round_robin","createdAt":"2022-08-15T16:05:25.815Z","updatedAt":"2022-09-29T19:13:13.853Z","locationIds":["aws-us-east-1"],"type":"browser","customProperties":null,"lastRunStatus":"pending","lastRunAt":null},{"id":489,"name":"Appinspect login API","active":true,"frequency":5,"schedulingStrategy":"round_robin","createdAt":"2022-08-16T15:47:43.730Z","updatedAt":"2022-08-16T15:47:43.741Z","locationIds":["aws-us-east-1"],"type":"api","customProperties":null,"lastRunStatus":"success","lastRunAt":"2024-04-11T20:12:54.000Z"},{"id":490,"name":"Arch Linux Packages","active":true,"frequency":10,"schedulingStrategy":"round_robin","createdAt":"2022-08-16T16:48:42.119Z","updatedAt":"2022-08-16T16:48:42.131Z","locationIds":["aws-us-east-1"],"type":"http","customProperties":null,"lastRunStatus":"pending","lastRunAt":null},{"id":492,"name":"Test of Splunkbase","active":true,"frequency":5,"schedulingStrategy":"round_robin","createdAt":"2022-08-16T19:35:54.014Z","updatedAt":"2022-09-29T19:13:13.907Z","locationIds":["aws-us-east-1"],"type":"browser","customProperties":null,"lastRunStatus":"success","lastRunAt":"2024-04-11T20:09:54.000Z"},{"id":493,"name":"Brewery API","active":true,"frequency":5,"schedulingStrategy":"round_robin","createdAt":"2022-08-16T19:44:15.626Z","updatedAt":"2022-08-16T19:44:15.635Z","locationIds":["aws-us-east-1"],"type":"api","customProperties":null,"lastRunStatus":"pending","lastRunAt":null},{"id":495,"name":"Multi-step test of legacy Splunkbase","active":true,"frequency":5,"schedulingStrategy":"round_robin","createdAt":"2022-08-17T01:24:44.579Z","updatedAt":"2022-09-29T19:13:13.203Z","locationIds":["aws-us-east-1"],"type":"browser","customProperties":null,"lastRunStatus":"pending","lastRunAt":null},{"id":496,"name":"Multi-step Test of new Splunkbase","active":true,"frequency":5,"schedulingStrategy":"round_robin","createdAt":"2022-08-17T01:33:27.771Z","updatedAt":"2022-09-29T19:13:13.997Z","locationIds":["aws-us-east-1"],"type":"browser","customProperties":null,"lastRunStatus":"pending","lastRunAt":null},{"id":935,"name":"This test does test stuff","active":true,"frequency":30,"schedulingStrategy":"round_robin","createdAt":"2022-10-26T14:48:36.026Z","updatedAt":"2022-10-26T14:48:36.037Z","locationIds":["aws-us-east-1"],"type":"api","customProperties":null,"lastRunStatus":"pending","lastRunAt":null},{"id":1116,"name":"boop-test","active":true,"frequency":5,"schedulingStrategy":"round_robin","createdAt":"2022-11-16T19:18:59.603Z","updatedAt":"2022-11-16T19:20:58.911Z","locationIds":["aws-us-east-1","aws-ap-northeast-1"],"type":"api","customProperties":null,"lastRunStatus":"success","lastRunAt":"2024-04-11T20:12:32.000Z"},{"id":1128,"name":"boopbeep","active":true,"frequency":5,"schedulingStrategy":"round_robin","createdAt":"2022-11-17T14:19:49.564Z","updatedAt":"2022-11-17T14:19:49.571Z","locationIds":["aws-us-east-1"],"type":"browser","customProperties":null,"lastRunStatus":"pending","lastRunAt":null}],"page":1,"per_page":50,"next_page_link":null,"total_count":10}`
3131
output = &ChecksV2Response{}
3232
)
3333

0 commit comments

Comments
 (0)