@@ -11,6 +11,7 @@ import (
11
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12
12
13
13
honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
14
+ "github.com/honeycombio/terraform-provider-honeycombio/internal/helper/test"
14
15
)
15
16
16
17
func TestAccDataSourceHoneycombioRecipient_basic (t * testing.T ) {
@@ -21,53 +22,53 @@ func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) {
21
22
{
22
23
Type : honeycombio .RecipientTypeEmail ,
23
24
Details : honeycombio.RecipientDetails {
24
- EmailAddress :
"[email protected] " ,
25
+ EmailAddress : test . RandomEmail () ,
25
26
},
26
27
},
27
28
{
28
29
Type : honeycombio .RecipientTypeEmail ,
29
30
Details : honeycombio.RecipientDetails {
30
- EmailAddress :
"[email protected] " ,
31
+ EmailAddress : test . RandomEmail () ,
31
32
},
32
33
},
33
34
{
34
35
Type : honeycombio .RecipientTypeSlack ,
35
36
Details : honeycombio.RecipientDetails {
36
- SlackChannel : "#acctest" ,
37
+ SlackChannel : test . RandomStringWithPrefix ( "#test." , 12 ) ,
37
38
},
38
39
},
39
40
{
40
41
Type : honeycombio .RecipientTypeSlack ,
41
42
Details : honeycombio.RecipientDetails {
42
- SlackChannel : "#tmp-acctest" ,
43
+ SlackChannel : test . RandomStringWithPrefix ( "#test." , 12 ) ,
43
44
},
44
45
},
45
46
{
46
47
Type : honeycombio .RecipientTypePagerDuty ,
47
48
Details : honeycombio.RecipientDetails {
48
- PDIntegrationKey : "6f05176bf1c7a1adb6ee516521770ec4" ,
49
- PDIntegrationName : "My Important Service" ,
49
+ PDIntegrationKey : test . RandomString ( 32 ) ,
50
+ PDIntegrationName : test . RandomStringWithPrefix ( "test." , 20 ) ,
50
51
},
51
52
},
52
53
{
53
54
Type : honeycombio .RecipientTypePagerDuty ,
54
55
Details : honeycombio.RecipientDetails {
55
- PDIntegrationKey : "6f05176bf1b7a1adb6ee516521770ac0" ,
56
- PDIntegrationName : "My Other Important Service" ,
56
+ PDIntegrationKey : test . RandomString ( 32 ) ,
57
+ PDIntegrationName : test . RandomStringWithPrefix ( "test." , 20 ) ,
57
58
},
58
59
},
59
60
{
60
61
Type : honeycombio .RecipientTypeWebhook ,
61
62
Details : honeycombio.RecipientDetails {
62
- WebhookName : "My Notifications Hook" ,
63
- WebhookSecret : "s0s3kret!" ,
63
+ WebhookName : test . RandomStringWithPrefix ( "test." , 16 ) ,
64
+ WebhookSecret : test . RandomString ( 20 ) ,
64
65
WebhookURL : "https://my.webhook.dev.corp.io" ,
65
66
},
66
67
},
67
68
{
68
69
Type : honeycombio .RecipientTypeMSTeams ,
69
70
Details : honeycombio.RecipientDetails {
70
- WebhookName : "My Teams Channel" ,
71
+ WebhookName : test . RandomStringWithPrefix ( "test." , 16 ) ,
71
72
WebhookURL : "https://outlook.office.com/webhook/12345" ,
72
73
},
73
74
},
@@ -92,57 +93,57 @@ func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) {
92
93
ProtoV5ProviderFactories : testAccProtoV5ProviderFactory ,
93
94
Steps : []resource.TestStep {
94
95
{
95
- Config :
testAccRecipientWithDeprecatedTarget (
"email" ,
"[email protected] " ),
96
- Check :
resource .
TestCheckResourceAttr (
"data.honeycombio_recipient.test" ,
"address" ,
"[email protected] " ),
96
+ Config : testAccRecipientWithDeprecatedTarget ("email" , testRecipients [ 0 ]. Details . EmailAddress ),
97
+ Check : resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "address" , testRecipients [ 0 ]. Details . EmailAddress ),
97
98
},
98
99
{
99
- Config : testAccRecipientWithDeprecatedTarget ("slack" , "#acctest" ),
100
- Check : resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "channel" , "#acctest" ),
100
+ Config : testAccRecipientWithDeprecatedTarget ("slack" , testRecipients [ 2 ]. Details . SlackChannel ),
101
+ Check : resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "channel" , testRecipients [ 2 ]. Details . SlackChannel ),
101
102
},
102
103
{
103
104
Config :
testAccRecipientWithDeprecatedTarget (
"email" ,
"[email protected] " ),
104
105
ExpectError : regexp .MustCompile ("your recipient query returned no results." ),
105
106
},
106
107
{
107
- Config :
testAccRecipientWithFilterValue (
"email" ,
"address" ,
"[email protected] " ),
108
- Check :
resource .
TestCheckResourceAttr (
"data.honeycombio_recipient.test" ,
"address" ,
"[email protected] " ),
108
+ Config : testAccRecipientWithFilterValue ("email" , "address" , testRecipients [ 1 ]. Details . EmailAddress ),
109
+ Check : resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "address" , testRecipients [ 1 ]. Details . EmailAddress ),
109
110
},
110
111
{
111
112
Config :
testAccRecipientWithFilterValue (
"email" ,
"address" ,
"[email protected] " ),
112
113
ExpectError : regexp .MustCompile ("your recipient query returned no results." ),
113
114
},
114
115
{
115
- Config : testAccRecipientWithFilterValue ("pagerduty" , "integration_name" , "My Important Service" ),
116
+ Config : testAccRecipientWithFilterValue ("pagerduty" , "integration_name" , testRecipients [ 4 ]. Details . PDIntegrationName ),
116
117
Check : resource .ComposeAggregateTestCheckFunc (
117
- resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "integration_name" , "My Important Service" ),
118
- resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "integration_key" , "6f05176bf1c7a1adb6ee516521770ec4" ),
118
+ resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "integration_name" , testRecipients [ 4 ]. Details . PDIntegrationName ),
119
+ resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "integration_key" , testRecipients [ 4 ]. Details . PDIntegrationKey ),
119
120
),
120
121
},
121
122
{
122
123
Config : testAccRecipientWithFilterRegex ("webhook" , "url" , ".*dev.corp.io" ),
123
124
Check : resource .ComposeAggregateTestCheckFunc (
124
- resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "name" , "My Notifications Hook" ),
125
- resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "secret" , "s0s3kret!" ),
125
+ resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "name" , testRecipients [ 6 ]. Details . WebhookName ),
126
+ resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "secret" , testRecipients [ 6 ]. Details . WebhookSecret ),
126
127
resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "url" , "https://my.webhook.dev.corp.io" ),
127
128
),
128
129
},
129
130
{
130
- Config : testAccRecipientWithFilterValue ("msteams" , "name" , "My Teams Channel" ),
131
+ Config : testAccRecipientWithFilterValue ("msteams" , "name" , testRecipients [ 7 ]. Details . WebhookName ),
131
132
Check : resource .ComposeAggregateTestCheckFunc (
132
- resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "name" , "My Teams Channel" ),
133
+ resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "name" , testRecipients [ 7 ]. Details . WebhookName ),
133
134
resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "url" , "https://outlook.office.com/webhook/12345" ),
134
135
),
135
136
},
136
137
{
137
- Config : testAccRecipientWithFilterValue ("slack" , "channel" , "#tmp-acctest" ),
138
- Check : resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "channel" , "#tmp-acctest" ),
138
+ Config : testAccRecipientWithFilterValue ("slack" , "channel" , testRecipients [ 3 ]. Details . SlackChannel ),
139
+ Check : resource .TestCheckResourceAttr ("data.honeycombio_recipient.test" , "channel" , testRecipients [ 3 ]. Details . SlackChannel ),
139
140
},
140
141
{
141
- Config : testAccRecipientWithFilterRegex ("email" , "address" , "^acctest* " ),
142
+ Config : testAccRecipientWithFilterRegex ("email" , "address" , ".*@example.com " ),
142
143
ExpectError : regexp .MustCompile ("your recipient query returned more than one result. Please try a more specific search criteria." ),
143
144
},
144
145
{
145
- Config : testAccRecipientWithFilterRegex ("pagerduty" , "integration_name" , "^.*Important Service$ " ),
146
+ Config : testAccRecipientWithFilterRegex ("pagerduty" , "integration_name" , ".* " ),
146
147
ExpectError : regexp .MustCompile ("your recipient query returned more than one result. Please try a more specific search criteria." ),
147
148
},
148
149
},
@@ -154,8 +155,7 @@ func testAccRecipientWithDeprecatedTarget(recipientType, target string) string {
154
155
data "honeycombio_recipient" "test" {
155
156
type = "%s"
156
157
target = "%s"
157
- }
158
- ` , recipientType , target )
158
+ }` , recipientType , target )
159
159
}
160
160
161
161
func testAccRecipientWithFilterValue (recipientType , filterName , filterValue string ) string {
@@ -167,8 +167,7 @@ data "honeycombio_recipient" "test" {
167
167
name = "%s"
168
168
value = "%s"
169
169
}
170
- }
171
- ` , recipientType , filterName , filterValue )
170
+ }` , recipientType , filterName , filterValue )
172
171
}
173
172
174
173
func testAccRecipientWithFilterRegex (recipientType , filterName , filterRegex string ) string {
@@ -180,6 +179,5 @@ data "honeycombio_recipient" "test" {
180
179
name = "%s"
181
180
value_regex = "%s"
182
181
}
183
- }
184
- ` , recipientType , filterName , filterRegex )
182
+ }` , recipientType , filterName , filterRegex )
185
183
}
0 commit comments