github.com/newrelic/newrelic-client-go@v1.1.0/pkg/synthetics/monitors_integration_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package synthetics 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 12 mock "github.com/newrelic/newrelic-client-go/pkg/testhelpers" 13 ) 14 15 var ( 16 testIntegrationMonitor = Monitor{ 17 Type: MonitorTypes.Ping, 18 Frequency: 15, 19 URI: "https://google.com", 20 Locations: []string{"AWS_US_EAST_1"}, 21 Status: MonitorStatus.Disabled, 22 SLAThreshold: 7, 23 UserID: 0, 24 APIVersion: "LATEST", 25 Options: MonitorOptions{}, 26 } 27 ) 28 29 func TestIntegrationMonitors(t *testing.T) { 30 t.Parallel() 31 32 tc := mock.NewIntegrationTestConfig(t) 33 34 synthetics := New(tc) 35 36 rand := mock.RandSeq(5) 37 testIntegrationMonitor.Name = fmt.Sprintf("test-synthetics-monitor-%s", rand) 38 39 // Test: Create 40 created, err := synthetics.CreateMonitor(testIntegrationMonitor) 41 42 require.NoError(t, err) 43 require.NotNil(t, created) 44 45 // Test: List 46 monitors, err := synthetics.ListMonitors() 47 48 require.NoError(t, err) 49 require.NotNil(t, monitors) 50 require.Greater(t, len(monitors), 0) 51 52 // Test: Get 53 monitorID := created.ID 54 monitor, err := synthetics.GetMonitor(monitorID) 55 56 require.NoError(t, err) 57 require.NotNil(t, *monitor) 58 59 // Test: Update 60 updatedName := fmt.Sprintf("test-synthetics-monitor-updated-%s", rand) 61 monitor.Name = updatedName 62 updated, err := synthetics.UpdateMonitor(*monitor) 63 64 require.NoError(t, err) 65 require.NotNil(t, *updated) 66 67 monitor, err = synthetics.GetMonitor(monitorID) 68 69 require.NoError(t, err) 70 require.Equal(t, updatedName, monitor.Name) 71 72 // Test: Delete 73 err = synthetics.DeleteMonitor(monitorID) 74 75 require.NoError(t, err) 76 }