-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from site24x7/main
Reverse merge
- Loading branch information
Showing
26 changed files
with
1,560 additions
and
33 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ jobs: | |
uses: goreleaser/[email protected] | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
args: release --clean | ||
env: | ||
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} | ||
# GitHub sets this automatically | ||
|
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,60 @@ | ||
package fake | ||
|
||
import ( | ||
"github.com/site24x7/terraform-provider-site24x7/api" | ||
"github.com/site24x7/terraform-provider-site24x7/api/endpoints/monitors" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
var _ monitors.CronMonitors = &CronMonitors{} | ||
|
||
type CronMonitors struct { | ||
mock.Mock | ||
} | ||
|
||
func (e *CronMonitors) Get(monitorID string) (*api.CronMonitor, error) { | ||
args := e.Called(monitorID) | ||
if obj, ok := args.Get(0).(*api.CronMonitor); ok { | ||
return obj, args.Error(1) | ||
} | ||
return nil, args.Error(1) | ||
} | ||
|
||
func (e *CronMonitors) Create(monitor *api.CronMonitor) (*api.CronMonitor, error) { | ||
args := e.Called(monitor) | ||
if obj, ok := args.Get(0).(*api.CronMonitor); ok { | ||
return obj, args.Error(1) | ||
} | ||
return nil, args.Error(1) | ||
} | ||
|
||
func (e *CronMonitors) Update(monitor *api.CronMonitor) (*api.CronMonitor, error) { | ||
args := e.Called(monitor) | ||
if obj, ok := args.Get(0).(*api.CronMonitor); ok { | ||
return obj, args.Error(1) | ||
} | ||
return nil, args.Error(1) | ||
} | ||
|
||
func (e *CronMonitors) Delete(monitorID string) error { | ||
args := e.Called(monitorID) | ||
return args.Error(0) | ||
} | ||
|
||
func (e *CronMonitors) List() ([]*api.CronMonitor, error) { | ||
args := e.Called() | ||
if obj, ok := args.Get(0).([]*api.CronMonitor); ok { | ||
return obj, args.Error(1) | ||
} | ||
return nil, args.Error(1) | ||
} | ||
|
||
func (e *CronMonitors) Activate(monitorID string) error { | ||
args := e.Called(monitorID) | ||
return args.Error(0) | ||
} | ||
|
||
func (e *CronMonitors) Suspend(monitorID string) error { | ||
args := e.Called(monitorID) | ||
return args.Error(0) | ||
} |
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,103 @@ | ||
package monitors | ||
|
||
import ( | ||
"github.com/site24x7/terraform-provider-site24x7/api" | ||
"github.com/site24x7/terraform-provider-site24x7/rest" | ||
) | ||
|
||
type CronMonitors interface { | ||
Get(monitorID string) (*api.CronMonitor, error) | ||
Create(monitor *api.CronMonitor) (*api.CronMonitor, error) | ||
Update(monitor *api.CronMonitor) (*api.CronMonitor, error) | ||
Delete(monitorID string) error | ||
List() ([]*api.CronMonitor, error) | ||
Activate(monitorID string) error | ||
Suspend(monitorID string) error | ||
} | ||
|
||
type cronMonitors struct { | ||
client rest.Client | ||
} | ||
|
||
func NewCronMonitors(client rest.Client) CronMonitors { | ||
return &cronMonitors{ | ||
client: client, | ||
} | ||
} | ||
|
||
func (c *cronMonitors) Get(monitorID string) (*api.CronMonitor, error) { | ||
monitor := &api.CronMonitor{} | ||
err := c.client. | ||
Get(). | ||
Resource("monitors"). | ||
ResourceID(monitorID). | ||
Do(). | ||
Parse(monitor) | ||
|
||
return monitor, err | ||
} | ||
|
||
func (c *cronMonitors) Create(monitor *api.CronMonitor) (*api.CronMonitor, error) { | ||
newMonitor := &api.CronMonitor{} | ||
err := c.client. | ||
Post(). | ||
Resource("monitors"). | ||
AddHeader("Content-Type", "application/json;charset=UTF-8"). | ||
Body(monitor). | ||
Do(). | ||
Parse(newMonitor) | ||
|
||
return newMonitor, err | ||
} | ||
|
||
func (c *cronMonitors) Update(monitor *api.CronMonitor) (*api.CronMonitor, error) { | ||
updatedMonitor := &api.CronMonitor{} | ||
err := c.client. | ||
Put(). | ||
Resource("monitors"). | ||
ResourceID(monitor.MonitorID). | ||
AddHeader("Content-Type", "application/json;charset=UTF-8"). | ||
Body(monitor). | ||
Do(). | ||
Parse(updatedMonitor) | ||
|
||
return updatedMonitor, err | ||
} | ||
|
||
func (c *cronMonitors) Delete(monitorID string) error { | ||
return c.client. | ||
Delete(). | ||
Resource("monitors"). | ||
ResourceID(monitorID). | ||
Do(). | ||
Err() | ||
} | ||
|
||
func (c *cronMonitors) List() ([]*api.CronMonitor, error) { | ||
cronMonitors := []*api.CronMonitor{} | ||
err := c.client. | ||
Get(). | ||
Resource("monitors"). | ||
Do(). | ||
Parse(&cronMonitors) | ||
|
||
return cronMonitors, err | ||
} | ||
|
||
func (c *cronMonitors) Activate(monitorID string) error { | ||
return c.client. | ||
Put(). | ||
Resource("monitors/activate"). | ||
ResourceID(monitorID). | ||
Do(). | ||
Err() | ||
} | ||
|
||
func (c *cronMonitors) Suspend(monitorID string) error { | ||
return c.client. | ||
Put(). | ||
Resource("monitors/suspend"). | ||
ResourceID(monitorID). | ||
Do(). | ||
Err() | ||
} |
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,152 @@ | ||
package monitors | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/site24x7/terraform-provider-site24x7/api" | ||
"github.com/site24x7/terraform-provider-site24x7/rest" | ||
"github.com/site24x7/terraform-provider-site24x7/validation" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCronMonitors(t *testing.T) { | ||
validation.RunTests(t, []*validation.EndpointTest{ | ||
{ | ||
Name: "create cron monitor", | ||
ExpectedVerb: "POST", | ||
ExpectedPath: "/monitors", | ||
ExpectedBody: validation.Fixture(t, "requests/create_cron_monitor.json"), | ||
StatusCode: 200, | ||
ResponseBody: validation.JsonAPIResponseBody(t, nil), | ||
Fn: func(t *testing.T, c rest.Client) { | ||
cronMonitor := &api.CronMonitor{ | ||
DisplayName: "foo", | ||
CronExpression: "* * * * *", | ||
CronTz: "IST", | ||
WaitTime: 30, | ||
Type: "CRON", | ||
ThresholdProfileID: "012", | ||
NotificationProfileID: "789", | ||
MonitorGroups: []string{"234", "567"}, | ||
UserGroupIDs: []string{"123", "456"}, | ||
TagIDs: []string{"123"}, | ||
ThirdPartyServiceIDs: []string{"123", "456"}, | ||
OnCallScheduleID: "1244", | ||
} | ||
|
||
_, err := NewCronMonitors(c).Create(cronMonitor) | ||
require.NoError(t, err) | ||
}, | ||
}, | ||
{ | ||
Name: "get cron monitor", | ||
ExpectedVerb: "GET", | ||
ExpectedPath: "/monitors/897654345678", | ||
StatusCode: 200, | ||
ResponseBody: validation.Fixture(t, "responses/get_cron_monitor.json"), | ||
Fn: func(t *testing.T, c rest.Client) { | ||
cronMonitor, err := NewCronMonitors(c).Get("897654345678") | ||
require.NoError(t, err) | ||
|
||
expected := &api.CronMonitor{ | ||
MonitorID: "897654345678", | ||
DisplayName: "foo", | ||
CronExpression: "* * * * *", | ||
CronTz: "IST", | ||
WaitTime: 30, | ||
Type: "CRON", | ||
ThresholdProfileID: "012", | ||
NotificationProfileID: "789", | ||
MonitorGroups: []string{"234", "567"}, | ||
UserGroupIDs: []string{"123", "456"}, | ||
ThirdPartyServiceIDs: []string{"123", "456"}, | ||
OnCallScheduleID: "1244", | ||
} | ||
|
||
assert.Equal(t, expected, cronMonitor) | ||
}, | ||
}, | ||
{ | ||
Name: "list cron monitors", | ||
ExpectedVerb: "GET", | ||
ExpectedPath: "/monitors", | ||
StatusCode: 200, | ||
ResponseBody: validation.Fixture(t, "responses/list_cron_monitors.json"), | ||
Fn: func(t *testing.T, c rest.Client) { | ||
cronMonitors, err := NewCronMonitors(c).List() | ||
require.NoError(t, err) | ||
|
||
expected := []*api.CronMonitor{ | ||
{ | ||
MonitorID: "897654345678", | ||
DisplayName: "foo", | ||
CronExpression: "* * * * *", | ||
CronTz: "IST", | ||
WaitTime: 30, | ||
Type: "CRON", | ||
ThresholdProfileID: "012", | ||
NotificationProfileID: "789", | ||
MonitorGroups: []string{"234", "567"}, | ||
UserGroupIDs: []string{"123", "456"}, | ||
ThirdPartyServiceIDs: []string{"123", "456"}, | ||
OnCallScheduleID: "1244", | ||
}, | ||
{ | ||
MonitorID: "933654345678", | ||
DisplayName: "foo", | ||
CronExpression: "* * * * *", | ||
CronTz: "IST", | ||
WaitTime: 30, | ||
Type: "CRON", | ||
ThresholdProfileID: "012", | ||
NotificationProfileID: "789", | ||
MonitorGroups: []string{"234", "567"}, | ||
UserGroupIDs: []string{"123", "456"}, | ||
ThirdPartyServiceIDs: []string{"123", "456"}, | ||
OnCallScheduleID: "1244", | ||
}, | ||
} | ||
|
||
assert.Equal(t, expected, cronMonitors) | ||
}, | ||
}, | ||
{ | ||
Name: "update cron monitor", | ||
ExpectedVerb: "PUT", | ||
ExpectedPath: "/monitors/123", | ||
ExpectedBody: validation.Fixture(t, "requests/update_cron_monitor.json"), | ||
StatusCode: 200, | ||
ResponseBody: validation.JsonAPIResponseBody(t, nil), | ||
Fn: func(t *testing.T, c rest.Client) { | ||
cronMonitor := &api.CronMonitor{ | ||
MonitorID: "123", | ||
DisplayName: "foo", | ||
CronExpression: "* * * * *", | ||
CronTz: "IST", | ||
WaitTime: 30, | ||
Type: "CRON", | ||
ThresholdProfileID: "012", | ||
NotificationProfileID: "789", | ||
MonitorGroups: []string{"234", "567"}, | ||
UserGroupIDs: []string{"123", "456"}, | ||
TagIDs: []string{"123"}, | ||
ThirdPartyServiceIDs: []string{"123", "456"}, | ||
OnCallScheduleID: "1244", | ||
} | ||
|
||
_, err := NewCronMonitors(c).Update(cronMonitor) | ||
require.NoError(t, err) | ||
}, | ||
}, | ||
{ | ||
Name: "delete cron monitor", | ||
ExpectedVerb: "DELETE", | ||
ExpectedPath: "/monitors/123", | ||
StatusCode: 200, | ||
Fn: func(t *testing.T, c rest.Client) { | ||
require.NoError(t, NewCronMonitors(c).Delete("123")) | ||
}, | ||
}, | ||
}) | ||
} |
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
Oops, something went wrong.