Skip to content

Commit ef618d2

Browse files
authored
chore: add recipients sweeper (#516)
Adds [Sweepers](https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/sweepers) to the project with an initial sweeper for recipients (which seem to cause the most test failures/conflicts). This also attempts to get all recipients named with a `test.` prefix (`#test.` for Slack recipients) establishing the convention that if a thing's name starts with `test.` is can be "swept". - Closes #446
1 parent 33da866 commit ef618d2

15 files changed

+252
-251
lines changed

.github/workflows/ci.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ jobs:
8484
TF_ACC_TERRAFORM_VERSION: ${{ env.TERRAFORM_VERSION }}
8585
run: go test -v -coverprofile=tf-coverage.txt -covermode=atomic ./internal/... ./honeycombio/...
8686

87+
- name: Cleanup Dangling Resources
88+
if: ${{ always() }}
89+
timeout-minutes: 5
90+
env:
91+
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }}
92+
HONEYCOMB_KEY_ID: ${{ secrets.HONEYCOMB_KEY_ID }}
93+
HONEYCOMB_KEY_SECRET: ${{ secrets.HONEYCOMB_KEY_SECRET }}
94+
HONEYCOMB_DATASET: testacc
95+
run: make sweep
96+
8797
- name: Generate Coverage Report
8898
uses: codecov/[email protected]
8999
with:
@@ -142,6 +152,17 @@ jobs:
142152
TF_ACC_TERRAFORM_VERSION: ${{ env.TERRAFORM_VERSION }}
143153
run: go test -v -coverprofile=tf-coverage.txt -covermode=atomic ./internal/... ./honeycombio/...
144154

155+
- name: Cleanup Dangling Resources
156+
if: ${{ always() }}
157+
timeout-minutes: 5
158+
env:
159+
HONEYCOMB_API_ENDPOINT: https://api.eu1.honeycomb.io
160+
HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY_EU }}
161+
HONEYCOMB_KEY_ID: ${{ secrets.HONEYCOMB_KEY_ID_EU }}
162+
HONEYCOMB_KEY_SECRET: ${{ secrets.HONEYCOMB_KEY_SECRET_EU }}
163+
HONEYCOMB_DATASET: testacc
164+
run: make sweep
165+
145166
- name: Generate Coverage Report
146167
uses: codecov/[email protected]
147168
with:

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ linters:
3535
- unconvert
3636
- unparam
3737
- unused
38-
- vet
38+
- govet
3939

4040
run:
4141
# Prevent false positive timeouts in CI

Makefile

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
1+
.PHONY: build testacc lint sweep
2+
default: testacc
3+
14
build:
25
go build -o terraform-provider-honeycombio
36

47
testacc:
58
TF_ACC=1 go test -v ./...
69

7-
fmt:
8-
goimports -l -w .
9-
go mod tidy
10-
terraform fmt --recursive
11-
12-
# Terraform 0.13+ only: build the repository and install the provider in one of
13-
# the local mirror directories following the new fileystem layout. Additionally,
14-
# we have to specify a version.
15-
#
16-
# https://www.terraform.io/docs/commands/cli-config.html#implied-local-mirror-directories
17-
# https://www.terraform.io/upgrade-guides/0-13.html#new-filesystem-layout-for-local-copies-of-providers
18-
19-
version = 99.0.0
20-
os_arch = $(shell go env GOOS)_$(shell go env GOARCH)
21-
provider_path = registry.terraform.io/honeycombio/honeycombio/$(version)/$(os_arch)/
22-
23-
install_macos:
24-
go build -o terraform-provider-honeycombio_$(version)
25-
26-
mkdir -p ~/Library/Application\ Support/io.terraform/plugins/$(provider_path)
27-
cp terraform-provider-honeycombio_$(version) ~/Library/Application\ Support/io.terraform/plugins/$(provider_path)
10+
lint:
11+
golangci-lint run
2812

29-
uninstall_macos:
30-
rm -r ~/Library/Application\ Support/io.terraform/plugins/registry.terraform.io/honeycombio
13+
sweep:
14+
# the sweep flag requires a string to be passed, but it is not used
15+
@echo "WARNING: This will destroy resources. Use only in development teams."
16+
go test ./internal/provider -v -timeout 5m -sweep=env
3117

32-
.PHONY: build testacc install

client/burn_alert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestBurnAlerts(t *testing.T) {
2121

2222
c := newTestClient(t)
2323
dataset := testDataset(t)
24-
testAlertEmail := test.RandomString(8) + "@example.com"
24+
testAlertEmail := test.RandomEmail()
2525

2626
sli, err := c.DerivedColumns.Create(ctx, dataset, &client.DerivedColumn{
2727
Alias: test.RandomStringWithPrefix("test.", 8),

client/query_annotation_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/stretchr/testify/require"
99

1010
"github.com/honeycombio/terraform-provider-honeycombio/client"
11+
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/test"
1112
)
1213

1314
func TestQueryAnnotations(t *testing.T) {
@@ -33,7 +34,7 @@ func TestQueryAnnotations(t *testing.T) {
3334

3435
t.Run("Create", func(t *testing.T) {
3536
data := &client.QueryAnnotation{
36-
Name: "Query created by a test",
37+
Name: test.RandomStringWithPrefix("test.", 20),
3738
Description: "This derived column is created by a test",
3839
QueryID: *query.ID,
3940
}
@@ -62,7 +63,7 @@ func TestQueryAnnotations(t *testing.T) {
6263
// change all the fields to test
6364
data := &client.QueryAnnotation{
6465
ID: queryAnnotation.ID,
65-
Name: "This is a new name for the query created by a test",
66+
Name: test.RandomStringWithPrefix("test.", 20),
6667
Description: "This is a new description",
6768
QueryID: *query.ID,
6869
}

client/recipient_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestRecipientsEmail(t *testing.T) {
2626
data := &client.Recipient{
2727
Type: client.RecipientTypeEmail,
2828
Details: client.RecipientDetails{
29-
EmailAddress: test.RandomString(8) + "@example.com",
29+
EmailAddress: test.RandomEmail(),
3030
},
3131
}
3232
now := time.Now()
@@ -56,7 +56,7 @@ func TestRecipientsEmail(t *testing.T) {
5656
})
5757

5858
t.Run("Update", func(t *testing.T) {
59-
rcpt.Details.EmailAddress = "[email protected]"
59+
rcpt.Details.EmailAddress = test.RandomEmail()
6060
now := time.Now()
6161
result, err := c.Recipients.Update(ctx, rcpt)
6262

client/v2/api_keys_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
hnyclient "github.com/honeycombio/terraform-provider-honeycombio/client"
1414
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper"
15+
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/test"
1516
)
1617

1718
func TestClient_APIKeys(t *testing.T) {
@@ -20,8 +21,9 @@ func TestClient_APIKeys(t *testing.T) {
2021
env := newTestEnvironment(ctx, t, c)
2122

2223
// create a new key
24+
keyName := test.RandomStringWithPrefix("test.", 10)
2325
k, err := c.APIKeys.Create(ctx, &APIKey{
24-
Name: helper.ToPtr("test key"),
26+
Name: helper.ToPtr(keyName),
2527
KeyType: "ingest",
2628
Environment: &Environment{
2729
ID: env.ID,
@@ -33,7 +35,7 @@ func TestClient_APIKeys(t *testing.T) {
3335
require.NoError(t, err)
3436
assert.NotEmpty(t, k.ID)
3537
assert.NotEmpty(t, k.Secret)
36-
assert.Equal(t, "test key", *k.Name)
38+
assert.Equal(t, keyName, *k.Name)
3739
assert.False(t, *k.Disabled)
3840
assert.True(t, k.Permissions.CreateDatasets)
3941

@@ -50,14 +52,15 @@ func TestClient_APIKeys(t *testing.T) {
5052
assert.WithinDuration(t, k.Timestamps.UpdatedAt, key.Timestamps.UpdatedAt, 5*time.Second)
5153

5254
// update the key's name and disable it
55+
keyName = test.RandomStringWithPrefix("test.", 10)
5356
key, err = c.APIKeys.Update(ctx, &APIKey{
5457
ID: k.ID,
55-
Name: helper.ToPtr("new name"),
58+
Name: helper.ToPtr(keyName),
5659
Disabled: helper.ToPtr(true),
5760
})
5861
require.NoError(t, err)
5962
assert.Equal(t, k.ID, key.ID)
60-
assert.Equal(t, "new name", *key.Name)
63+
assert.Equal(t, keyName, *key.Name)
6164
assert.True(t, *key.Disabled)
6265
assert.WithinDuration(t, time.Now(), key.Timestamps.UpdatedAt, time.Second)
6366

honeycombio/data_source_recipient_test.go

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1212

1313
honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
14+
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper/test"
1415
)
1516

1617
func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) {
@@ -21,53 +22,53 @@ func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) {
2122
{
2223
Type: honeycombio.RecipientTypeEmail,
2324
Details: honeycombio.RecipientDetails{
24-
EmailAddress: "[email protected]",
25+
EmailAddress: test.RandomEmail(),
2526
},
2627
},
2728
{
2829
Type: honeycombio.RecipientTypeEmail,
2930
Details: honeycombio.RecipientDetails{
30-
EmailAddress: "[email protected]",
31+
EmailAddress: test.RandomEmail(),
3132
},
3233
},
3334
{
3435
Type: honeycombio.RecipientTypeSlack,
3536
Details: honeycombio.RecipientDetails{
36-
SlackChannel: "#acctest",
37+
SlackChannel: test.RandomStringWithPrefix("#test.", 12),
3738
},
3839
},
3940
{
4041
Type: honeycombio.RecipientTypeSlack,
4142
Details: honeycombio.RecipientDetails{
42-
SlackChannel: "#tmp-acctest",
43+
SlackChannel: test.RandomStringWithPrefix("#test.", 12),
4344
},
4445
},
4546
{
4647
Type: honeycombio.RecipientTypePagerDuty,
4748
Details: honeycombio.RecipientDetails{
48-
PDIntegrationKey: "6f05176bf1c7a1adb6ee516521770ec4",
49-
PDIntegrationName: "My Important Service",
49+
PDIntegrationKey: test.RandomString(32),
50+
PDIntegrationName: test.RandomStringWithPrefix("test.", 20),
5051
},
5152
},
5253
{
5354
Type: honeycombio.RecipientTypePagerDuty,
5455
Details: honeycombio.RecipientDetails{
55-
PDIntegrationKey: "6f05176bf1b7a1adb6ee516521770ac0",
56-
PDIntegrationName: "My Other Important Service",
56+
PDIntegrationKey: test.RandomString(32),
57+
PDIntegrationName: test.RandomStringWithPrefix("test.", 20),
5758
},
5859
},
5960
{
6061
Type: honeycombio.RecipientTypeWebhook,
6162
Details: honeycombio.RecipientDetails{
62-
WebhookName: "My Notifications Hook",
63-
WebhookSecret: "s0s3kret!",
63+
WebhookName: test.RandomStringWithPrefix("test.", 16),
64+
WebhookSecret: test.RandomString(20),
6465
WebhookURL: "https://my.webhook.dev.corp.io",
6566
},
6667
},
6768
{
6869
Type: honeycombio.RecipientTypeMSTeams,
6970
Details: honeycombio.RecipientDetails{
70-
WebhookName: "My Teams Channel",
71+
WebhookName: test.RandomStringWithPrefix("test.", 16),
7172
WebhookURL: "https://outlook.office.com/webhook/12345",
7273
},
7374
},
@@ -92,57 +93,57 @@ func TestAccDataSourceHoneycombioRecipient_basic(t *testing.T) {
9293
ProtoV5ProviderFactories: testAccProtoV5ProviderFactory,
9394
Steps: []resource.TestStep{
9495
{
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),
9798
},
9899
{
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),
101102
},
102103
{
103104
Config: testAccRecipientWithDeprecatedTarget("email", "[email protected]"),
104105
ExpectError: regexp.MustCompile("your recipient query returned no results."),
105106
},
106107
{
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),
109110
},
110111
{
111112
Config: testAccRecipientWithFilterValue("email", "address", "[email protected]"),
112113
ExpectError: regexp.MustCompile("your recipient query returned no results."),
113114
},
114115
{
115-
Config: testAccRecipientWithFilterValue("pagerduty", "integration_name", "My Important Service"),
116+
Config: testAccRecipientWithFilterValue("pagerduty", "integration_name", testRecipients[4].Details.PDIntegrationName),
116117
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),
119120
),
120121
},
121122
{
122123
Config: testAccRecipientWithFilterRegex("webhook", "url", ".*dev.corp.io"),
123124
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),
126127
resource.TestCheckResourceAttr("data.honeycombio_recipient.test", "url", "https://my.webhook.dev.corp.io"),
127128
),
128129
},
129130
{
130-
Config: testAccRecipientWithFilterValue("msteams", "name", "My Teams Channel"),
131+
Config: testAccRecipientWithFilterValue("msteams", "name", testRecipients[7].Details.WebhookName),
131132
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),
133134
resource.TestCheckResourceAttr("data.honeycombio_recipient.test", "url", "https://outlook.office.com/webhook/12345"),
134135
),
135136
},
136137
{
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),
139140
},
140141
{
141-
Config: testAccRecipientWithFilterRegex("email", "address", "^acctest*"),
142+
Config: testAccRecipientWithFilterRegex("email", "address", ".*@example.com"),
142143
ExpectError: regexp.MustCompile("your recipient query returned more than one result. Please try a more specific search criteria."),
143144
},
144145
{
145-
Config: testAccRecipientWithFilterRegex("pagerduty", "integration_name", "^.*Important Service$"),
146+
Config: testAccRecipientWithFilterRegex("pagerduty", "integration_name", ".*"),
146147
ExpectError: regexp.MustCompile("your recipient query returned more than one result. Please try a more specific search criteria."),
147148
},
148149
},
@@ -154,8 +155,7 @@ func testAccRecipientWithDeprecatedTarget(recipientType, target string) string {
154155
data "honeycombio_recipient" "test" {
155156
type = "%s"
156157
target = "%s"
157-
}
158-
`, recipientType, target)
158+
}`, recipientType, target)
159159
}
160160

161161
func testAccRecipientWithFilterValue(recipientType, filterName, filterValue string) string {
@@ -167,8 +167,7 @@ data "honeycombio_recipient" "test" {
167167
name = "%s"
168168
value = "%s"
169169
}
170-
}
171-
`, recipientType, filterName, filterValue)
170+
}`, recipientType, filterName, filterValue)
172171
}
173172

174173
func testAccRecipientWithFilterRegex(recipientType, filterName, filterRegex string) string {
@@ -180,6 +179,5 @@ data "honeycombio_recipient" "test" {
180179
name = "%s"
181180
value_regex = "%s"
182181
}
183-
}
184-
`, recipientType, filterName, filterRegex)
182+
}`, recipientType, filterName, filterRegex)
185183
}

0 commit comments

Comments
 (0)