github.com/newrelic/newrelic-client-go@v1.1.0/pkg/alerts/synthetics_conditions_integration_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package alerts 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 12 "github.com/newrelic/newrelic-client-go/pkg/synthetics" 13 mock "github.com/newrelic/newrelic-client-go/pkg/testhelpers" 14 ) 15 16 func TestIntegrationSyntheticsConditions(t *testing.T) { 17 t.Parallel() 18 19 tc := mock.NewIntegrationTestConfig(t) 20 21 var ( 22 testRandStr = mock.RandSeq(5) 23 testIntegrationSyntheticsMonitor = synthetics.Monitor{ 24 Name: fmt.Sprintf("test-synthetics-alert-conditions-monitor-%s", testRandStr), 25 Type: synthetics.MonitorTypes.Ping, 26 Frequency: 15, 27 URI: "https://google.com", 28 Locations: []string{"AWS_US_EAST_1"}, 29 Status: synthetics.MonitorStatus.Enabled, 30 SLAThreshold: 7, 31 APIVersion: "LATEST", 32 } 33 testIntegrationPolicy = Policy{ 34 Name: fmt.Sprintf("test-synthetics-alert-conditions-policy-%s", testRandStr), 35 IncidentPreference: "PER_POLICY", 36 } 37 testIntegrationSyntheticsCondition = SyntheticsCondition{ 38 Name: fmt.Sprintf("test-synthetics-alert-condition-%s", testRandStr), 39 } 40 ) 41 42 alerts := newIntegrationTestClient(t) 43 synth := synthetics.New(tc) 44 45 // Setup 46 monitor, err := synth.CreateMonitor(testIntegrationSyntheticsMonitor) 47 48 require.NoError(t, err) 49 50 policy, err := alerts.CreatePolicy(testIntegrationPolicy) 51 52 require.NoError(t, err) 53 54 // Deferred Teardown 55 defer func() { 56 // Teardown 57 _, err = alerts.DeletePolicy(policy.ID) 58 if err != nil { 59 t.Logf("Error cleaning up alert policy %d (%s): %s", policy.ID, policy.Name, err) 60 } 61 62 err = synth.DeleteMonitor(monitor.ID) 63 if err != nil { 64 t.Logf("Error cleaning up synthetics monitor %s (%s): %s", 65 monitor.ID, testIntegrationSyntheticsMonitor.Name, err) 66 } 67 }() 68 69 // Test: Create 70 testIntegrationSyntheticsCondition.MonitorID = monitor.ID 71 created, err := alerts.CreateSyntheticsCondition(policy.ID, testIntegrationSyntheticsCondition) 72 73 require.NoError(t, err) 74 require.NotZero(t, created) 75 76 // Test: List 77 conditions, err := alerts.ListSyntheticsConditions(policy.ID) 78 79 require.NoError(t, err) 80 require.NotZero(t, conditions) 81 82 // Test: Get 83 condition, err := alerts.GetSyntheticsCondition(policy.ID, conditions[0].ID) 84 85 require.NoError(t, err) 86 require.NotZero(t, condition) 87 88 // Test: Update 89 condition.Name = fmt.Sprintf("test-synthetics-alert-condition-updated-%s", testRandStr) 90 updated, err := alerts.UpdateSyntheticsCondition(*condition) 91 92 require.NoError(t, err) 93 require.NotZero(t, updated) 94 95 // Test: Delete 96 deleted, err := alerts.DeleteSyntheticsCondition(updated.ID) 97 98 require.NoError(t, err) 99 require.NotZero(t, deleted) 100 }