github.com/newrelic/newrelic-client-go@v1.1.0/pkg/alerts/infrastructure_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 TestIntegrationListInfrastructureConditions(t *testing.T) { 16 t.Parallel() 17 18 var ( 19 testIntegrationInfrastructureConditionRandStr = nr.RandSeq(5) 20 testIntegrationInfrastructureConditionPolicy = Policy{ 21 Name: fmt.Sprintf("test-integration-infrastructure-conditions-%s", 22 testIntegrationInfrastructureConditionRandStr), 23 IncidentPreference: "PER_POLICY", 24 } 25 thresholdZeroValue = float64(0) 26 testIntegrationInfrastructureConditionThreshold = InfrastructureConditionThreshold{ 27 Duration: 6, 28 Value: &thresholdZeroValue, 29 } 30 31 testIntegrationInfrastructureCondition = InfrastructureCondition{ 32 Comparison: "equal", 33 Critical: &testIntegrationInfrastructureConditionThreshold, 34 Enabled: true, 35 Name: "Java is running", 36 ProcessWhere: "(commandName = 'java')", 37 Type: "infra_process_running", 38 Where: "(hostname LIKE '%cassandra%')", 39 Description: "Mozzarella halloumi the big cheese cottage cheese cheese and biscuits cheeseburger fromage frais roquefort.", 40 } 41 ) 42 43 alerts := newIntegrationTestClient(t) 44 45 // Setup 46 policy, err := alerts.CreatePolicy(testIntegrationInfrastructureConditionPolicy) 47 48 require.NoError(t, err) 49 50 // Deferred teardown 51 defer func() { 52 _, err := alerts.DeletePolicy(policy.ID) 53 54 if err != nil { 55 t.Logf("error cleaning up alert policy %d (%s): %s", policy.ID, policy.Name, err) 56 } 57 }() 58 59 // Test: Create 60 testIntegrationInfrastructureCondition.PolicyID = policy.ID 61 created, err := alerts.CreateInfrastructureCondition(testIntegrationInfrastructureCondition) 62 63 require.NoError(t, err) 64 require.NotZero(t, created) 65 66 // Test: List 67 conditions, err := alerts.ListInfrastructureConditions(policy.ID) 68 69 require.NoError(t, err) 70 require.Greater(t, len(conditions), 0) 71 72 // Test: Get 73 condition, err := alerts.GetInfrastructureCondition(created.ID) 74 75 require.NoError(t, err) 76 require.NotZero(t, condition) 77 78 // Test: Update 79 created.Name = "Updated" 80 created.Description = "" 81 updated, err := alerts.UpdateInfrastructureCondition(*created) 82 83 require.NoError(t, err) 84 require.NotZero(t, updated) 85 require.Equal(t, "", updated.Description) 86 87 // Test: Delete 88 err = alerts.DeleteInfrastructureCondition(created.ID) 89 90 require.NoError(t, err) 91 }