Skip to content

Commit

Permalink
Merge branch 'v2' into PENG-3135/add_redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
fformica authored Mar 8, 2024
2 parents ca8c96d + 2b174a2 commit 9918bc0
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.9.0 (March 7th, 2024)

FEATURES:

* Adds support for listing available monitoring regions

## 2.8.0 (February 14th, 2024)

FEATURES:
Expand Down
18 changes: 18 additions & 0 deletions mockns1/monitor_regions.go
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,
)
}
4 changes: 3 additions & 1 deletion rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
clientVersion = "2.8.0"
clientVersion = "2.9.0"

defaultEndpoint = "https://api.nsone.net/v1/"
defaultShouldFollowPagination = true
Expand Down Expand Up @@ -65,6 +65,7 @@ type Client struct {
DataFeeds *DataFeedsService
DataSources *DataSourcesService
Jobs *JobsService
MonitorRegions *MonitorRegionsService
PulsarJobs *PulsarJobsService
Notifications *NotificationsService
Records *RecordsService
Expand Down Expand Up @@ -114,6 +115,7 @@ func NewClient(httpClient Doer, options ...func(*Client)) *Client {
c.DataFeeds = (*DataFeedsService)(&c.common)
c.DataSources = (*DataSourcesService)(&c.common)
c.Jobs = (*JobsService)(&c.common)
c.MonitorRegions = (*MonitorRegionsService)(&c.common)
c.PulsarJobs = (*PulsarJobsService)(&c.common)
c.Notifications = (*NotificationsService)(&c.common)
c.Records = (*RecordsService)(&c.common)
Expand Down
8 changes: 8 additions & 0 deletions rest/model/monitor/region.go
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"`
}
29 changes: 29 additions & 0 deletions rest/monitor_regions.go
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, &regions)
if err != nil {
return nil, resp, err
}

return regions, resp, nil
}
45 changes: 45 additions & 0 deletions rest/monitor_regions_test.go
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))
})
})
}

0 comments on commit 9918bc0

Please sign in to comment.