Skip to content

Commit

Permalink
Merge pull request #11 from bgustafson/bg/SYN-3197_adds_custom_proper…
Browse files Browse the repository at this point in the history
…ties

SYN-3197: Custom Properties
  • Loading branch information
greatestusername-splunk authored Nov 14, 2023
2 parents 0b7d26e + 46fadd4 commit 68e4c5d
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 108 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@

.DS_Store
.vscode/settings.json

# Jetbrains IDEs
.idea
184 changes: 99 additions & 85 deletions syntheticsclientv2/common_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ type Validations struct {
}

type Tests []struct {
Active bool `json:"active"`
Createdat time.Time `json:"createdAt"`
Frequency int `json:"frequency"`
ID int `json:"id"`
Locationids []string `json:"locationIds"`
Name string `json:"name"`
Schedulingstrategy string `json:"schedulingStrategy"`
Type string `json:"type"`
Updatedat time.Time `json:"updatedAt"`
Active bool `json:"active"`
Createdat time.Time `json:"createdAt"`
Frequency int `json:"frequency"`
ID int `json:"id"`
Locationids []string `json:"locationIds"`
Name string `json:"name"`
Schedulingstrategy string `json:"schedulingStrategy"`
Type string `json:"type"`
Updatedat time.Time `json:"updatedAt"`
Customproperties []CustomProperties `json:"customProperties"`
}

type GetChecksV2Options struct {
Expand Down Expand Up @@ -237,86 +238,91 @@ type ChecksV2Response struct {

type PortCheckV2Response struct {
Test struct {
ID int `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Frequency int `json:"frequency"`
SchedulingStrategy string `json:"schedulingStrategy"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
LocationIds []string `json:"locationIds"`
Type string `json:"type"`
Protocol string `json:"protocol"`
Host string `json:"host"`
Port int `json:"port"`
ID int `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Frequency int `json:"frequency"`
SchedulingStrategy string `json:"schedulingStrategy"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
LocationIds []string `json:"locationIds"`
Type string `json:"type"`
Protocol string `json:"protocol"`
Host string `json:"host"`
Port int `json:"port"`
Customproperties []CustomProperties `json:"customProperties"`
} `json:"test"`
}

type PortCheckV2Input struct {
Test struct {
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url"`
Port int `json:"port"`
Protocol string `json:"protocol"`
Host string `json:"host"`
LocationIds []string `json:"locationIds"`
Frequency int `json:"frequency"`
SchedulingStrategy string `json:"schedulingStrategy"`
Active bool `json:"active"`
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url"`
Port int `json:"port"`
Protocol string `json:"protocol"`
Host string `json:"host"`
LocationIds []string `json:"locationIds"`
Frequency int `json:"frequency"`
SchedulingStrategy string `json:"schedulingStrategy"`
Active bool `json:"active"`
Customproperties []CustomProperties `json:"customProperties"`
} `json:"test"`
}

type HttpCheckV2Response struct {
Test struct {
ID int `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Frequency int `json:"frequency"`
SchedulingStrategy string `json:"schedulingStrategy"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
LocationIds []string `json:"locationIds"`
Type string `json:"type"`
URL string `json:"url"`
RequestMethod string `json:"requestMethod"`
Body string `json:"body,omitempty"`
Authentication *Authentication `json:"authentication"`
UserAgent *string `json:"userAgent"`
Verifycertificates bool `json:"verifyCertificates"`
HttpHeaders []HttpHeaders `json:"headers,omitempty"`
Validations []Validations `json:"validations"`
ID int `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
Frequency int `json:"frequency"`
SchedulingStrategy string `json:"schedulingStrategy"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
LocationIds []string `json:"locationIds"`
Type string `json:"type"`
URL string `json:"url"`
RequestMethod string `json:"requestMethod"`
Body string `json:"body,omitempty"`
Authentication *Authentication `json:"authentication"`
UserAgent *string `json:"userAgent"`
Verifycertificates bool `json:"verifyCertificates"`
HttpHeaders []HttpHeaders `json:"headers,omitempty"`
Validations []Validations `json:"validations"`
Customproperties []CustomProperties `json:"customProperties"`
} `json:"test"`
}

type HttpCheckV2Input struct {
Test struct {
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url"`
LocationIds []string `json:"locationIds"`
Frequency int `json:"frequency"`
SchedulingStrategy string `json:"schedulingStrategy"`
Active bool `json:"active"`
RequestMethod string `json:"requestMethod"`
Body string `json:"body,omitempty"`
Authentication *Authentication `json:"authentication"`
UserAgent *string `json:"userAgent"`
Verifycertificates bool `json:"verifyCertificates"`
HttpHeaders []HttpHeaders `json:"headers,omitempty"`
Validations []Validations `json:"validations"`
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url"`
LocationIds []string `json:"locationIds"`
Frequency int `json:"frequency"`
SchedulingStrategy string `json:"schedulingStrategy"`
Active bool `json:"active"`
RequestMethod string `json:"requestMethod"`
Body string `json:"body,omitempty"`
Authentication *Authentication `json:"authentication"`
UserAgent *string `json:"userAgent"`
Verifycertificates bool `json:"verifyCertificates"`
HttpHeaders []HttpHeaders `json:"headers,omitempty"`
Validations []Validations `json:"validations"`
Customproperties []CustomProperties `json:"customProperties"`
} `json:"test"`
}

type ApiCheckV2Input struct {
Test struct {
Active bool `json:"active"`
Deviceid int `json:"deviceId"`
Frequency int `json:"frequency"`
Locationids []string `json:"locationIds"`
Name string `json:"name"`
Requests []Requests `json:"requests"`
Schedulingstrategy string `json:"schedulingStrategy"`
Active bool `json:"active"`
Deviceid int `json:"deviceId"`
Frequency int `json:"frequency"`
Locationids []string `json:"locationIds"`
Name string `json:"name"`
Requests []Requests `json:"requests"`
Schedulingstrategy string `json:"schedulingStrategy"`
Customproperties []CustomProperties `json:"customProperties"`
} `json:"test"`
}

Expand All @@ -325,14 +331,15 @@ type ApiCheckV2Response struct {
Active bool `json:"active"`
Createdat time.Time `json:"createdAt"`
Device `json:"device,omitempty"`
Frequency int `json:"frequency,omitempty"`
ID int `json:"id,omitempty"`
Locationids []string `json:"locationIds,omitempty"`
Name string `json:"name,omitempty"`
Requests []Requests `json:"requests,omitempty"`
Schedulingstrategy string `json:"schedulingStrategy,omitempty"`
Type string `json:"type,omitempty"`
Updatedat time.Time `json:"updatedAt,omitempty"`
Frequency int `json:"frequency,omitempty"`
ID int `json:"id,omitempty"`
Locationids []string `json:"locationIds,omitempty"`
Name string `json:"name,omitempty"`
Requests []Requests `json:"requests,omitempty"`
Schedulingstrategy string `json:"schedulingStrategy,omitempty"`
Type string `json:"type,omitempty"`
Updatedat time.Time `json:"updatedAt,omitempty"`
Customproperties []CustomProperties `json:"customProperties"`
}
}

Expand All @@ -348,6 +355,7 @@ type BrowserCheckV2Input struct {
Schedulingstrategy string `json:"schedulingStrategy"`
Active bool `json:"active"`
Advancedsettings `json:"advancedSettings,omitempty"`
Customproperties []CustomProperties `json:"customProperties"`
} `json:"test"`
}

Expand All @@ -357,13 +365,19 @@ type BrowserCheckV2Response struct {
Advancedsettings `json:"advancedSettings"`
Createdat time.Time `json:"createdAt"`
Device `json:"device"`
Frequency int `json:"frequency"`
ID int `json:"id"`
Locationids []string `json:"locationIds"`
Name string `json:"name"`
Schedulingstrategy string `json:"schedulingStrategy"`
Transactions []Transactions `json:"transactions"`
Type string `json:"type"`
Updatedat time.Time `json:"updatedAt"`
Frequency int `json:"frequency"`
ID int `json:"id"`
Locationids []string `json:"locationIds"`
Name string `json:"name"`
Schedulingstrategy string `json:"schedulingStrategy"`
Transactions []Transactions `json:"transactions"`
Type string `json:"type"`
Updatedat time.Time `json:"updatedAt"`
Customproperties []CustomProperties `json:"customProperties"`
} `json:"test"`
}

type CustomProperties struct {
Key string `json:"key"`
Value string `json:"value"`
}
5 changes: 4 additions & 1 deletion syntheticsclientv2/create_apicheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

var (
createApiV2Body = `{"test":{"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":{"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"}]}]}}`
inputData = ApiCheckV2Input{}
)

Expand Down Expand Up @@ -79,4 +79,7 @@ func TestCreateApiCheckV2(t *testing.T) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Schedulingstrategy, inputData.Test.Schedulingstrategy)
}

if !reflect.DeepEqual(resp.Test.Customproperties, inputData.Test.Customproperties) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Customproperties, inputData.Test.Customproperties)
}
}
5 changes: 4 additions & 1 deletion syntheticsclientv2/create_browsercheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

var (
createBrowserCheckV2Body = `{"test":{"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"},"waitForNav":true},{"name":"click","type":"click_element","selectorType":"id","selector":"clicky","waitForNav":true},{"name":"fill in fieldz","type":"enter_value","selectorType":"id","selector":"beep","value":"{{env.beep-var}}","waitForNav":false},{"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},{"name":"Select-val-text","type":"select_option","selectorType":"id","selector":"textzz","optionSelectorType":"text","optionSelector":"sdad","waitForNav":false},{"name":"Select-Val-Val","type":"select_option","selectorType":"id","selector":"valz","optionSelectorType":"value","optionSelector":"{{env.beep-var}}","waitForNav":false},{"name":"Run JS","type":"run_javascript","value":"beeeeeeep","waitForNav":true},{"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}]}],"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"}]}}}`
createBrowserCheckV2Body = `{"test":{"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"},"waitForNav":true},{"name":"click","type":"click_element","selectorType":"id","selector":"clicky","waitForNav":true},{"name":"fill in fieldz","type":"enter_value","selectorType":"id","selector":"beep","value":"{{env.beep-var}}","waitForNav":false},{"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},{"name":"Select-val-text","type":"select_option","selectorType":"id","selector":"textzz","optionSelectorType":"text","optionSelector":"sdad","waitForNav":false},{"name":"Select-Val-Val","type":"select_option","selectorType":"id","selector":"valz","optionSelectorType":"value","optionSelector":"{{env.beep-var}}","waitForNav":false},{"name":"Run JS","type":"run_javascript","value":"beeeeeeep","waitForNav":true},{"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}]}],"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"}]}}}`
inputBrowserCheckV2Data = BrowserCheckV2Input{}
)

Expand Down Expand Up @@ -83,4 +83,7 @@ func TestCreateBrowserCheckV2(t *testing.T) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Schedulingstrategy, inputBrowserCheckV2Data.Test.Schedulingstrategy)
}

if !reflect.DeepEqual(resp.Test.Customproperties, inputBrowserCheckV2Data.Test.Customproperties) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Customproperties, inputBrowserCheckV2Data.Test.Customproperties)
}
}
5 changes: 4 additions & 1 deletion syntheticsclientv2/create_httpcheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

var (
createHttpCheckV2Body = `{"test":{"name":"morebeeps-test","type":"http","url":"https://www.splunk.com","location_ids":["aws-us-east-1"],"frequency":10,"scheduling_strategy":"round_robin","active":true,"request_method":"GET","body":null,"headers":[{"name":"boop","value":"beep"}]}}`
createHttpCheckV2Body = `{"test":{"customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "name":"morebeeps-test","type":"http","url":"https://www.splunk.com","location_ids":["aws-us-east-1"],"frequency":10,"scheduling_strategy":"round_robin","active":true,"request_method":"GET","body":null,"headers":[{"name":"boop","value":"beep"}]}}`
inputHttpCheckV2Data = HttpCheckV2Input{}
)

Expand Down Expand Up @@ -83,4 +83,7 @@ func TestCreateHttpCheckV2(t *testing.T) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.SchedulingStrategy, inputHttpCheckV2Data.Test.SchedulingStrategy)
}

if !reflect.DeepEqual(resp.Test.Customproperties, inputHttpCheckV2Data.Test.Customproperties) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Customproperties, inputHttpCheckV2Data.Test.Customproperties)
}
}
5 changes: 4 additions & 1 deletion syntheticsclientv2/create_portcheckv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

var (
createPortCheckV2Body = `{"test":{"name":"splunk - port 443","type":"port","url":"","port":443,"protocol":"tcp","host":"www.splunk.com","location_ids":["aws-us-east-1"],"frequency":10,"scheduling_strategy":"round_robin","active":true}}`
createPortCheckV2Body = `{"test":{"customProperties": [{"key": "Test_Key", "value": "Test Custom Properties"}], "name":"splunk - port 443","type":"port","url":"","port":443,"protocol":"tcp","host":"www.splunk.com","location_ids":["aws-us-east-1"],"frequency":10,"scheduling_strategy":"round_robin","active":true}}`
inputPortCheckV2Data = PortCheckV2Input{}
)

Expand Down Expand Up @@ -83,4 +83,7 @@ func TestCreatePortCheckV2(t *testing.T) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp.Test.Port, inputPortCheckV2Data.Test.Port)
}

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

0 comments on commit 68e4c5d

Please sign in to comment.