github.com/newrelic/newrelic-client-go@v1.1.0/pkg/alerts/policy_channels_test.go (about) 1 //go:build unit 2 // +build unit 3 4 package alerts 5 6 import ( 7 "net/http" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 var ( 14 testUpdatePolicyChannelsResponseJSON = `{ 15 "policy": { 16 "id": 593436, 17 "channel_ids": [ 18 2932701, 19 2932702 20 ] 21 } 22 }` 23 24 testDeletePolicyChannelResponseJSON = `{ 25 "channel": { 26 "id": 2932701, 27 "name": "test@example.com", 28 "type": "email", 29 "configuration": { 30 "include_json_attachment": "true", 31 "recipients": "test@example.com" 32 }, 33 "links": { 34 "policy_ids": [ 35 593436 36 ] 37 } 38 }, 39 "links": { 40 "channel.policy_ids": "/v2/policies/{policy_id}" 41 } 42 }` 43 ) 44 45 func TestUpdatePolicyChannels(t *testing.T) { 46 t.Parallel() 47 alerts := newMockResponse(t, testUpdatePolicyChannelsResponseJSON, http.StatusOK) 48 49 actual, err := alerts.UpdatePolicyChannels(593436, []int{2932701, 2932702}) 50 51 expected := PolicyChannels{ 52 ID: 593436, 53 ChannelIDs: []int{2932701, 2932702}, 54 } 55 56 assert.NoError(t, err) 57 assert.Equal(t, expected, *actual) 58 } 59 60 func TestDeletePolicyChannel(t *testing.T) { 61 t.Parallel() 62 alerts := newMockResponse(t, testDeletePolicyChannelResponseJSON, http.StatusOK) 63 64 expected := Channel{ 65 ID: 2932701, 66 Name: "test@example.com", 67 Type: "email", 68 Configuration: ChannelConfiguration{ 69 IncludeJSONAttachment: "true", 70 Recipients: "test@example.com", 71 }, 72 Links: ChannelLinks{ 73 PolicyIDs: []int{593436}, 74 }, 75 } 76 77 actual, err := alerts.DeletePolicyChannel(593436, 2932701) 78 79 assert.NoError(t, err) 80 assert.Equal(t, expected, *actual) 81 }