Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/splunk/syntheticsclient/v2

go 1.14
go 1.16
49 changes: 27 additions & 22 deletions syntheticsclientv2/common_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,29 @@ type BusinessTransactions struct {
StepsV2 []StepsV2 `json:"steps"`
}

// Selector is a v2 browser step element locator (type + value).
type Selector struct {
Type string `json:"type"`
Value string `json:"value"`
}

type StepsV2 struct {
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url,omitempty"`
Action string `json:"action,omitempty"`
WaitForNav bool `json:"waitForNav"`
WaitForNavTimeout int `json:"waitForNavTimeout,omitempty"`
WaitForNavTimeoutDefault bool `json:"waitForNavTimeoutDefault,omitempty"`
MaxWaitTime int `json:"maxWaitTime,omitempty"`
MaxWaitTimeDefault bool `json:"maxWaitTimeDefault,omitempty"`
SelectorType string `json:"selectorType,omitempty"`
Selector string `json:"selector,omitempty"`
OptionSelectorType string `json:"optionSelectorType,omitempty"`
OptionSelector string `json:"optionSelector,omitempty"`
VariableName string `json:"variableName,omitempty"`
Value string `json:"value,omitempty"`
Options Options `json:"options,omitempty"`
Duration int `json:"duration,omitempty"`
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url,omitempty"`
Action string `json:"action,omitempty"`
WaitForNav bool `json:"waitForNav"`
WaitForNavTimeout int `json:"waitForNavTimeout,omitempty"`
WaitForNavTimeoutDefault bool `json:"waitForNavTimeoutDefault,omitempty"`
MaxWaitTime int `json:"maxWaitTime,omitempty"`
MaxWaitTimeDefault bool `json:"maxWaitTimeDefault,omitempty"`
Selectors []Selector `json:"selectors,omitempty"`
OptionSelectorType string `json:"optionSelectorType,omitempty"`
OptionSelector string `json:"optionSelector,omitempty"`
VariableName string `json:"variableName,omitempty"`
Value string `json:"value,omitempty"`
Options Options `json:"options,omitempty"`
Duration int `json:"duration,omitempty"`
}

type Options struct {
Expand Down Expand Up @@ -416,9 +421,9 @@ type ApiCheckV2Input struct {

type ApiCheckV2Response struct {
Test struct {
Active bool `json:"active"`
Createdat time.Time `json:"createdAt"`
Device `json:"device,omitempty"`
Active bool `json:"active"`
Createdat time.Time `json:"createdAt"`
Deviceid int `json:"deviceId,omitempty"`
Frequency int `json:"frequency,omitempty"`
ID int `json:"id,omitempty"`
Locationids []string `json:"locationIds,omitempty"`
Expand Down Expand Up @@ -460,8 +465,8 @@ type BrowserCheckV2Response struct {
type BrowserCheckV2ResponseTest struct {
Active bool `json:"active"`
Advancedsettings `json:"advancedSettings"`
Createdat time.Time `json:"createdAt"`
Device `json:"device"`
Createdat time.Time `json:"createdAt"`
Deviceid int `json:"deviceId"`
Frequency int `json:"frequency"`
ID int `json:"id"`
Locationids []string `json:"locationIds"`
Expand Down
2 changes: 1 addition & 1 deletion syntheticsclientv2/create_apicheckv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c Client) CreateApiCheckV2(ApiCheckV2Details *ApiCheckV2Input) (*ApiCheckV
return nil, nil, err
}

details, err := c.makePublicAPICall("POST", "/tests/api", bytes.NewBuffer(body), nil)
details, err := c.makePublicAPICall("POST", "/v2/tests/api", bytes.NewBuffer(body), nil)
if err != nil {
return nil, details, err
}
Expand Down
4 changes: 2 additions & 2 deletions syntheticsclientv2/create_apicheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import (
)

var (
createApiV2Body = `{"test":{"automaticRetries": 1,"customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "active":true,"device_id":1,"frequency":5,"location_ids":["aws-us-east-1"],"name":"boop-test","scheduling_strategy":"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"}]}]}}`
createApiV2Body = `{"test":{"automaticRetries": 1,"customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "active":true,"deviceId":1,"frequency":5,"location_ids":["aws-us-east-1"],"name":"boop-test","scheduling_strategy":"round_robin","requests":[{"configuration":{"name":"Get-Test","requestMethod":"GET","url":"https://api.us1.signalfx.com/v2/synthetics/v2/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"}]}]}}`
inputData = ApiCheckV2Input{}
)

func TestCreateApiCheckV2(t *testing.T) {
setup()
defer teardown()

testMux.HandleFunc("/tests/api", func(w http.ResponseWriter, r *http.Request) {
testMux.HandleFunc("/v2/tests/api", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
_, err := w.Write([]byte(createApiV2Body))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion syntheticsclientv2/create_browsercheckv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c Client) CreateBrowserCheckV2(browserCheckV2Details *BrowserCheckV2Input)
return nil, nil, err
}

details, err := c.makePublicAPICall("POST", "/tests/browser", bytes.NewBuffer(body), nil)
details, err := c.makePublicAPICall("POST", "/v2/tests/browser", bytes.NewBuffer(body), nil)
if err != nil {
return nil, details, err
}
Expand Down
4 changes: 2 additions & 2 deletions syntheticsclientv2/create_browsercheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ import (
)

var (
createBrowserCheckV2Body = `{"test":{"automaticRetries": 1, "customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "name":"browser-beep-test","transactions":[{"name":"Synthetic transaction 1","steps":[{"name":"Go to URL","type":"go_to_url","url":"https://splunk.com","action":"go_to_url","options":{"url":"https://splunk.com"}},{"name":"click","type":"click_element","selectorType":"id","selector":"clicky","waitForNav":true,"waitForNavTimeout":2000},{"name":"fill in fieldz","type":"enter_value","selectorType":"id","selector":"beep","value":"{{env.beep-var}}","waitForNav":false,"waitForNavTimeout":50},{"name":"accept---Alert","type":"accept_alert"},{"name":"Select-Val-Index","type":"select_option","selectorType":"id","selector":"selectionz","optionSelectorType":"index","optionSelector":"{{env.beep-var}}","waitForNav":false,"waitForNavTimeout":50},{"name":"Select-val-text","type":"select_option","selectorType":"id","selector":"textzz","optionSelectorType":"text","optionSelector":"sdad","waitForNav":false,"waitForNavTimeout":50},{"name":"Select-Val-Val","type":"select_option","selectorType":"id","selector":"valz","optionSelectorType":"value","optionSelector":"{{env.beep-var}}","waitForNav":false,"waitForNavTimeout":50},{"name":"Run JS","type":"run_javascript","value":"beeeeeeep","waitForNav":true,"waitForNavTimeout":2000},{"name":"Save as text","type":"store_variable_from_element","selectorType":"link","selector":"beepval","variableName":"{{env.terraform-test-foo-301}}"},{"name":"Save JS return Val","type":"store_variable_from_javascript","value":"sdasds","variableName":"{{env.terraform-test-foo-301}}","waitForNav":true,"waitForNavTimeout":2000}]}],"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"}],"chromeFlags":[{"name":"--proxy-bypass-list","value":"127.0.0.1:8080"}],"cookies":[{"key":"super","value":"duper","domain":"www.batmansagent.com","path":"/boom/goes/beep"}],"excludedFiles":[{"type":"google_analytics"},{"type":"custom","regex":"some-domain.com"},{"type":"all_except","regex":"another-domain.com"}]}}}`
createBrowserCheckV2Body = `{"test":{"automaticRetries": 1, "customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "name":"browser-beep-test","transactions":[{"name":"Synthetic transaction 1","steps":[{"name":"Go to URL","type":"go_to_url","url":"https://splunk.com","action":"go_to_url","options":{"url":"https://splunk.com"}},{"name":"click","type":"click_element","selectors":[{"type":"id","value":"clicky"}],"waitForNav":true,"waitForNavTimeout":2000},{"name":"fill in fieldz","type":"enter_value","selectors":[{"type":"id","value":"beep"}],"value":"{{env.beep-var}}","waitForNav":false,"waitForNavTimeout":50},{"name":"accept---Alert","type":"accept_alert"},{"name":"Select-Val-Index","type":"select_option","selectors":[{"type":"id","value":"selectionz"}],"optionSelectorType":"index","optionSelector":"{{env.beep-var}}","waitForNav":false,"waitForNavTimeout":50},{"name":"Select-val-text","type":"select_option","selectors":[{"type":"id","value":"textzz"}],"optionSelectorType":"text","optionSelector":"sdad","waitForNav":false,"waitForNavTimeout":50},{"name":"Select-Val-Val","type":"select_option","selectors":[{"type":"id","value":"valz"}],"optionSelectorType":"value","optionSelector":"{{env.beep-var}}","waitForNav":false,"waitForNavTimeout":50},{"name":"Run JS","type":"run_javascript","value":"beeeeeeep","waitForNav":true,"waitForNavTimeout":2000},{"name":"Save as text","type":"store_variable_from_element","selectors":[{"type":"link","value":"beepval"}],"variableName":"{{env.terraform-test-foo-301}}"},{"name":"Save JS return Val","type":"store_variable_from_javascript","value":"sdasds","variableName":"{{env.terraform-test-foo-301}}","waitForNav":true,"waitForNavTimeout":2000}]}],"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"}],"chromeFlags":[{"name":"--proxy-bypass-list","value":"127.0.0.1:8080"}],"cookies":[{"key":"super","value":"duper","domain":"www.batmansagent.com","path":"/boom/goes/beep"}],"excludedFiles":[{"type":"google_analytics"},{"type":"custom","regex":"some-domain.com"},{"type":"all_except","regex":"another-domain.com"}]}}}`
inputBrowserCheckV2Data = BrowserCheckV2Input{}
)

func TestCreateBrowserCheckV2(t *testing.T) {
setup()
defer teardown()

testMux.HandleFunc("/tests/browser", func(w http.ResponseWriter, r *http.Request) {
testMux.HandleFunc("/v2/tests/browser", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
_, err := w.Write([]byte(createBrowserCheckV2Body))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion syntheticsclientv2/delete_apicheckv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func (c Client) DeleteApiCheckV2(id int) (int, error) {
requestDetails, err := c.makePublicAPICall("DELETE", fmt.Sprintf("/tests/api/%d", id), bytes.NewBufferString("{}"), nil)
requestDetails, err := c.makePublicAPICall("DELETE", fmt.Sprintf("/v2/tests/api/%d", id), bytes.NewBufferString("{}"), nil)
if err != nil {
return 1, err
}
Expand Down
2 changes: 1 addition & 1 deletion syntheticsclientv2/delete_apicheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestDeleteApiCheckV2(t *testing.T) {
setup()
defer teardown()

testMux.HandleFunc("/tests/api/19", func(w http.ResponseWriter, r *http.Request) {
testMux.HandleFunc("/v2/tests/api/19", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
_, err := w.Write([]byte(deleteApiCheckV2RespBody))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion syntheticsclientv2/delete_browsercheckv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func (c Client) DeleteBrowserCheckV2(id int) (int, error) {
requestDetails, err := c.makePublicAPICall("DELETE", fmt.Sprintf("/tests/browser/%d", id), bytes.NewBufferString("{}"), nil)
requestDetails, err := c.makePublicAPICall("DELETE", fmt.Sprintf("/v2/tests/browser/%d", id), bytes.NewBufferString("{}"), nil)
if err != nil {
return 1, err
}
Expand Down
2 changes: 1 addition & 1 deletion syntheticsclientv2/delete_browsercheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestDeleteBrowserCheckV2(t *testing.T) {
setup()
defer teardown()

testMux.HandleFunc("/tests/browser/19", func(w http.ResponseWriter, r *http.Request) {
testMux.HandleFunc("/v2/tests/browser/19", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
_, err := w.Write([]byte(deleteBrowserCheckV2RespBody))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion syntheticsclientv2/get_apicheckv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func parseApiCheckV2Response(response string) (*ApiCheckV2Response, error) {
func (c Client) GetApiCheckV2(id int) (*ApiCheckV2Response, *RequestDetails, error) {

details, err := c.makePublicAPICall("GET",
fmt.Sprintf("/tests/api/%d", id),
fmt.Sprintf("/v2/tests/api/%d", id),
bytes.NewBufferString("{}"),
nil)

Expand Down
12 changes: 4 additions & 8 deletions syntheticsclientv2/get_apicheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import (
)

var (
getApiCheckV2Body = `{"test":{"id":489,"name":"Appinspect login API","active":true, "automaticRetries": 1, "customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-08-16T15:47:43.730Z","updated_at":"2022-08-16T15:47:43.741Z","lastRunAt":"2024-03-07T00:47:43.741Z","lastRunStatus":"success","createdBy":"abc1234","updatedBy":"abc1234","location_ids":["aws-us-east-1"],"type":"api","device":{"id":1,"label":"Desktop","user_agent":"Mozilla/5.0 (X11; Linux x86_64; Splunk Synthetics) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36","viewport_width":1366,"viewport_height":768,"network_connection":{"description":"Standard Cable","upload_bandwidth":5000,"download_bandwidth":20000,"latency":28,"packet_loss":null}},"requests":[{"configuration":{"name":"Login","url":"https://api.splunk.com/2.0/rest/login/splunk","requestMethod":"GET","headers":{},"body":null},"setup":[],"validations":[]}]}}`
getApiCheckV2Body = `{"test":{"id":489,"name":"Appinspect login API","active":true, "automaticRetries": 1, "customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "frequency":5,"scheduling_strategy":"round_robin","created_at":"2022-08-16T15:47:43.730Z","updated_at":"2022-08-16T15:47:43.741Z","lastRunAt":"2024-03-07T00:47:43.741Z","lastRunStatus":"success","createdBy":"abc1234","updatedBy":"abc1234","location_ids":["aws-us-east-1"],"type":"api","deviceId":1,"requests":[{"configuration":{"name":"Login","url":"https://api.splunk.com/2.0/rest/login/splunk","requestMethod":"GET","headers":{},"body":null},"setup":[],"validations":[]}]}}`
inputGetApiCheckV2 = verifyApiCheckV2Input(string(getApiCheckV2Body))
)

func TestGetApiCheckV2(t *testing.T) {
setup()
defer teardown()

testMux.HandleFunc("/tests/api/489", func(w http.ResponseWriter, r *http.Request) {
testMux.HandleFunc("/v2/tests/api/489", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
_, err := w.Write([]byte(getApiCheckV2Body))
if err != nil {
Expand Down Expand Up @@ -74,12 +74,8 @@ func TestGetApiCheckV2(t *testing.T) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Updatedat, inputGetApiCheckV2.Test.Updatedat)
}

if !reflect.DeepEqual(resp.Test.Device, inputGetApiCheckV2.Test.Device) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Device, inputGetApiCheckV2.Test.Device)
}

if !reflect.DeepEqual(resp.Test.Device.Viewportheight, inputGetApiCheckV2.Test.Device.Viewportheight) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Device.Viewportheight, inputGetApiCheckV2.Test.Device.Viewportheight)
if !reflect.DeepEqual(resp.Test.Deviceid, inputGetApiCheckV2.Test.Deviceid) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Deviceid, inputGetApiCheckV2.Test.Deviceid)
}

if !reflect.DeepEqual(resp.Test.Requests, inputGetApiCheckV2.Test.Requests) {
Expand Down
2 changes: 1 addition & 1 deletion syntheticsclientv2/get_browsercheckv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func parseGetBrowserCheckV2Response(response string) (*BrowserCheckV2Response, e
}

func (c Client) GetBrowserCheckV2(id int) (*BrowserCheckV2Response, *RequestDetails, error) {
details, err := c.makePublicAPICall("GET", fmt.Sprintf("/tests/browser/%d", id), bytes.NewBufferString("{}"), nil)
details, err := c.makePublicAPICall("GET", fmt.Sprintf("/v2/tests/browser/%d", id), bytes.NewBufferString("{}"), nil)

// Check for errors
if err != nil {
Expand Down
Loading
Loading