-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v2' into PENG-3135/add_redirect
- Loading branch information
Showing
6 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package mockns1 | ||
|
||
import ( | ||
"net/http" | ||
|
||
"gopkg.in/ns1/ns1-go.v2/rest/model/monitor" | ||
) | ||
|
||
// AddMonitorRegionsListTestCase sets up a test case for the api.Client.MonitorRegionsService.List() function. | ||
func (s *Service) AddMonitorRegionsListTestCase( | ||
requestHeaders, responseHeaders http.Header, | ||
response []*monitor.Region, | ||
) error { | ||
return s.AddTestCase( | ||
http.MethodGet, "/monitoring/regions", http.StatusOK, requestHeaders, | ||
responseHeaders, "", response, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package monitor | ||
|
||
// Region wraps an NS1 /monitoring/regions resource. | ||
type Region struct { | ||
Code string `json:"code"` | ||
Name string `json:"name"` | ||
Subnets []string `json:"subnets"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package rest | ||
|
||
import ( | ||
"net/http" | ||
|
||
"gopkg.in/ns1/ns1-go.v2/rest/model/monitor" | ||
) | ||
|
||
// MonitorRegionsService handles 'monitoring/regions' endpoint. | ||
type MonitorRegionsService service | ||
|
||
// List returns all available monitoring regions. | ||
// | ||
// API docs: https://developer.ibm.com/apis/catalog/ns1--ibm-ns1-connect-api/api/API--ns1--ibm-ns1-connect-api#listMonitoringRegions | ||
func (s *MonitorRegionsService) List() ([]*monitor.Region, *http.Response, error) { | ||
req, err := s.client.NewRequest("GET", "monitoring/regions", nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
regions := []*monitor.Region{} | ||
|
||
resp, err := s.client.Do(req, ®ions) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return regions, resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package rest_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"gopkg.in/ns1/ns1-go.v2/mockns1" | ||
api "gopkg.in/ns1/ns1-go.v2/rest" | ||
"gopkg.in/ns1/ns1-go.v2/rest/model/monitor" | ||
) | ||
|
||
func TestMonitorRegionsService(t *testing.T) { | ||
mock, doer, err := mockns1.New(t) | ||
require.Nil(t, err) | ||
defer mock.Shutdown() | ||
|
||
client := api.NewClient(doer, api.SetEndpoint("https://"+mock.Address+"/v1/")) | ||
|
||
t.Run("List", func(t *testing.T) { | ||
t.Run("Success", func(t *testing.T) { | ||
defer mock.ClearTestCases() | ||
|
||
mockRegions := []*monitor.Region{ | ||
{ | ||
Code: "lga", | ||
Name: "New York", | ||
Subnets: []string{"1.2.3.4/24"}, | ||
}, | ||
{ | ||
Code: "sjc", | ||
Name: "San Jose", | ||
Subnets: []string{"5.6.7.8/24"}, | ||
}, | ||
} | ||
|
||
require.Nil(t, mock.AddMonitorRegionsListTestCase(nil, nil, mockRegions)) | ||
|
||
regions, resp, err := client.MonitorRegions.List() | ||
|
||
require.Nil(t, err) | ||
require.Equal(t, 200, resp.StatusCode) | ||
require.Len(t, regions, len(mockRegions)) | ||
}) | ||
}) | ||
} |