github.com/newrelic/newrelic-client-go@v1.1.0/pkg/nrqldroprules/nrqldroprules_integration_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package nrqldroprules 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 11 mock "github.com/newrelic/newrelic-client-go/pkg/testhelpers" 12 ) 13 14 func TestIntegrationDropRules(t *testing.T) { 15 t.Parallel() 16 17 testAccountID, err := mock.GetTestAccountID() 18 if err != nil { 19 t.Skipf("%s", err) 20 } 21 22 var ( 23 rand = mock.RandSeq(5) 24 testRuleDescription = "testRuleDescription_" + rand 25 testOtherRuleDescription = "testRuleOtherDescription_" + rand 26 testRuleNrql = "SELECT * FROM Log WHERE container_name = 'noise'" 27 testCreateInput = []NRQLDropRulesCreateDropRuleInput{ 28 { 29 Description: testRuleDescription, 30 NRQL: testRuleNrql, 31 Action: NRQLDropRulesActionTypes.DROP_DATA, 32 }, 33 { 34 Description: testOtherRuleDescription, 35 NRQL: testRuleNrql, 36 Action: NRQLDropRulesActionTypes.DROP_DATA, 37 }, 38 } 39 ) 40 41 client := newIntegrationTestClient(t) 42 43 // Test: Create 44 created, err := client.NRQLDropRulesCreate(testAccountID, testCreateInput) 45 46 require.NoError(t, err) 47 require.NotNil(t, created) 48 require.NotEmpty(t, created) 49 require.Equal(t, 2, len(created.Successes)) 50 51 // Test: List 52 rules, err := client.GetList(testAccountID) 53 require.NoError(t, err) 54 require.Greater(t, len(rules.Rules), 0) 55 56 // Test: Delete 57 testDeleteInput := []string{created.Successes[0].ID, created.Successes[1].ID} 58 deleted, err := client.NRQLDropRulesDelete(testAccountID, testDeleteInput) 59 60 require.NoError(t, err) 61 require.NotNil(t, deleted) 62 require.NotEmpty(t, deleted) 63 require.Equal(t, 2, len(deleted.Successes)) 64 } 65 66 func newIntegrationTestClient(t *testing.T) Nrqldroprules { 67 tc := mock.NewIntegrationTestConfig(t) 68 69 return New(tc) 70 }