Skip to content

Commit

Permalink
Add GetSyntheticsTestsByType
Browse files Browse the repository at this point in the history
  • Loading branch information
btoueg committed Apr 10, 2019
1 parent 5497235 commit ec066ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions integration/synthetics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestSyntheticsUpdateRemovingTags(t *testing.T) {
}

func TestSyntheticsGetAllTests(t *testing.T) {
syntheticsTests, err := client.GetSyntheticsTests()
syntheticsTests, err := client.GetSyntheticsTestsByType("api")
if err != nil {
t.Fatalf("Retrieving synthetics tests failed when it shouldn't: %s", err)
}
Expand All @@ -87,7 +87,7 @@ func TestSyntheticsGetAllTests(t *testing.T) {
syntheticsTest := createTestSynthetics(t)
defer cleanUpSynthetics(t, syntheticsTest.GetPublicId())

syntheticsTests, err = client.GetSyntheticsTests()
syntheticsTests, err = client.GetSyntheticsTestsByType("api")
if err != nil {
t.Fatalf("Retrieving synthetics tests failed when it shouldn't: %s", err)
}
Expand Down
16 changes: 15 additions & 1 deletion synthetics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datadog

import (
"fmt"
"net/url"
)

// SyntheticsTest represents a synthetics test, either api or browser
Expand Down Expand Up @@ -81,7 +82,20 @@ type ToggleStatus struct {
// GetSyntheticsTests get all tests of type API
func (client *Client) GetSyntheticsTests() ([]SyntheticsTest, error) {
var out SyntheticsTestsList
if err := client.doJsonRequest("GET", "/v1/synthetics/tests?type=api", nil, &out); err != nil {
if err := client.doJsonRequest("GET", "/v1/synthetics/tests", nil, &out); err != nil {
return nil, err
}
return out.SyntheticsTests, nil
}

// GetSyntheticsTestsByType get all tests by type (e.g. api or browser)
func (client *Client) GetSyntheticsTestsByType(testType string) ([]SyntheticsTest, error) {
var out SyntheticsTestsList
query, err := url.ParseQuery(fmt.Sprintf("type=%v", testType))
if err != nil {
return nil, err
}
if err := client.doJsonRequest("GET", fmt.Sprintf("/v1/synthetics/tests?%v", query.Encode()), nil, &out); err != nil {
return nil, err
}
return out.SyntheticsTests, nil
Expand Down

0 comments on commit ec066ec

Please sign in to comment.