github.com/newrelic/newrelic-client-go@v1.1.0/pkg/alerts/multi_location_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 nr "github.com/newrelic/newrelic-client-go/pkg/testhelpers" 13 ) 14 15 func TestIntegrationMultiLocationSyntheticsConditions(t *testing.T) { 16 t.Parallel() 17 18 var ( 19 testIntegrationInfrastructureConditionRandStr = nr.RandSeq(5) 20 testIntegrationInfrastructureConditionPolicy = Policy{ 21 Name: fmt.Sprintf("test-integration-location-failure-condition-%s", 22 testIntegrationInfrastructureConditionRandStr), 23 IncidentPreference: "PER_POLICY", 24 } 25 26 testIntegrationMultiLocationSyntheticsCondition = MultiLocationSyntheticsCondition{ 27 Name: fmt.Sprintf("test-integration-location-failure-condition-%s", testIntegrationInfrastructureConditionRandStr), 28 Enabled: false, 29 Terms: []MultiLocationSyntheticsConditionTerm{ 30 {"warning", 10}, 31 {"critical", 11}, 32 }, 33 } 34 ) 35 36 alerts := newIntegrationTestClient(t) 37 38 // Setup 39 policy, err := alerts.CreatePolicy(testIntegrationInfrastructureConditionPolicy) 40 require.NoError(t, err) 41 42 // Deferred teardown 43 defer func() { 44 _, err := alerts.DeletePolicy(policy.ID) 45 46 if err != nil { 47 t.Logf("error cleaning up alert policy %d (%s): %s", policy.ID, policy.Name, err) 48 } 49 }() 50 51 // Test: Create 52 created, err := alerts.CreateMultiLocationSyntheticsCondition(testIntegrationMultiLocationSyntheticsCondition, policy.ID) 53 require.NoError(t, err) 54 require.NotZero(t, created) 55 56 defer func() { 57 _, err := alerts.DeleteMultiLocationSyntheticsCondition(created.ID) 58 if err != nil { 59 t.Logf("error cleaning up location failure condition %d (%s): %s", policy.ID, policy.Name, err) 60 } 61 }() 62 63 // Test: List 64 conditions, err := alerts.ListMultiLocationSyntheticsConditions(policy.ID) 65 66 require.NoError(t, err) 67 require.Greater(t, len(conditions), 0) 68 69 // TEMPORARILY DISABLED UNTIL UPSTREAM API IS FIXED 70 // Test: Update 71 // created.Name = "Updated" 72 // created.Enabled = true 73 // updated, err := alerts.UpdateMultiLocationSyntheticsCondition(*created) 74 75 // require.NoError(t, err) 76 // require.NotZero(t, updated) 77 78 }