Skip to content

Commit 9cdbcd6

Browse files
committed
Add more sweepers
1 parent 88fe18d commit 9cdbcd6

19 files changed

+1448
-186
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ test:
2424
# Acceptance tests. This will create, manage and delete real resources in a real
2525
# Buildkite organization!
2626
testacc:
27-
SWEEP=1 TF_ACC=1 go run gotest.tools/gotestsum --format testname --junitfile "junit-${BUILDKITE_JOB_ID}.xml" -- -parallel=4 ./...
27+
@echo "--- Running acceptance tests..."
28+
-TF_ACC=1 go run gotest.tools/gotestsum --format testname --junitfile "junit-${BUILDKITE_JOB_ID}.xml" -- -parallel=4 ./buildkite
29+
@echo "--- Running sweepers..."
30+
TF_ACC=1 go test ./buildkite -v -sweep=global -sweep-run=.
2831

2932
# Generate the Buildkite GraphQL schema file
3033
schema:

buildkite/provider_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
genqlient "github.com/Khan/genqlient/graphql"
99
"github.com/hashicorp/terraform-plugin-framework/providerserver"
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
11+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1112
"github.com/shurcooL/graphql"
1213
)
1314

@@ -17,6 +18,10 @@ var (
1718
organizationID string
1819
)
1920

21+
func TestMain(m *testing.M) {
22+
resource.TestMain(m)
23+
}
24+
2025
func init() {
2126
rt := http.DefaultTransport
2227
header := make(http.Header)

buildkite/resource_agent_token_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestAccBuildkiteAgentToken(t *testing.T) {
14-
RegisterResourceTracking(t)
14+
1515
basic := func(name string) string {
1616
return fmt.Sprintf(`
1717
provider "buildkite" {
@@ -124,8 +124,6 @@ func testAccCheckAgentTokenExists(resourceName string, resourceToken *AgentToken
124124
return fmt.Errorf("No ID is set in state")
125125
}
126126

127-
TrackResource("buildkite_agent_token", resourceState.Primary.ID)
128-
129127
var query struct {
130128
Node struct {
131129
AgentToken AgentTokenNode `graphql:"... on AgentToken"`
@@ -172,8 +170,6 @@ func testAccCheckAgentTokenResourceDestroy(s *terraform.State) error {
172170
if rs.Type != "buildkite_agent_token" {
173171
continue
174172
}
175-
176-
UntrackResource("buildkite_agent_token", rs.Primary.ID)
177173
}
178174
return nil
179175
}

buildkite/resource_cluster_agent_token_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
)
1414

1515
func TestAccBuildkiteClusterAgentTokenResource(t *testing.T) {
16-
RegisterResourceTracking(t)
1716
configBasic := func(fields ...string) string {
1817
return fmt.Sprintf(`
1918
provider "buildkite" {
@@ -84,7 +83,7 @@ func TestAccBuildkiteClusterAgentTokenResource(t *testing.T) {
8483
resource.ParallelTest(t, resource.TestCase{
8584
PreCheck: func() { testAccPreCheck(t) },
8685
ProtoV6ProviderFactories: protoV6ProviderFactories(),
87-
CheckDestroy: testAccCheckAgentTokenDestroyWithUntracking,
86+
CheckDestroy: testAccCheckAgentTokenDestroy,
8887
Steps: []resource.TestStep{
8988
{
9089
Config: configBasic(clusterName, tokenDesc),
@@ -122,7 +121,7 @@ func TestAccBuildkiteClusterAgentTokenResource(t *testing.T) {
122121
resource.ParallelTest(t, resource.TestCase{
123122
PreCheck: func() { testAccPreCheck(t) },
124123
ProtoV6ProviderFactories: protoV6ProviderFactories(),
125-
CheckDestroy: testAccCheckAgentTokenDestroyWithUntracking,
124+
CheckDestroy: testAccCheckAgentTokenDestroy,
126125
Steps: []resource.TestStep{
127126
{
128127
Config: configAllowedIPsBasic(clusterName, tokenDesc, allowedIps),
@@ -159,7 +158,7 @@ func TestAccBuildkiteClusterAgentTokenResource(t *testing.T) {
159158
resource.ParallelTest(t, resource.TestCase{
160159
PreCheck: func() { testAccPreCheck(t) },
161160
ProtoV6ProviderFactories: protoV6ProviderFactories(),
162-
CheckDestroy: testAccCheckAgentTokenDestroyWithUntracking,
161+
CheckDestroy: testAccCheckAgentTokenDestroy,
163162
Steps: []resource.TestStep{
164163
{
165164
Config: configBasic(clusterName, tokenDesc),
@@ -185,9 +184,6 @@ func testAccCheckClusterAgentTokenExists(resourceName string, ct *clusterAgentTo
185184
if resourceState.Primary.ID == "" {
186185
return fmt.Errorf("No ID is set in state")
187186
}
188-
189-
TrackResource("buildkite_cluster_agent_token", resourceState.Primary.ID)
190-
191187
clusterTokens, err := getClusterAgentTokens(
192188
context.Background(),
193189
genqlientGraphql,
@@ -227,14 +223,12 @@ func testAccCheckClusterAgentTokenRemoteValues(ct *clusterAgentTokenResourceMode
227223
}
228224
}
229225

230-
// Modify function name to prevent recursion
231-
func testAccCheckAgentTokenDestroyWithUntracking(s *terraform.State) error {
226+
func testAccCheckAgentTokenDestroy(s *terraform.State) error {
232227
for _, rs := range s.RootModule().Resources {
233228
if rs.Type != "buildkite_cluster_agent_token" {
234229
continue
235230
}
236231

237-
UntrackResource("buildkite_cluster_agent_token", rs.Primary.ID)
238232
}
239233
return nil
240234
}

buildkite/resource_cluster_default_queue_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
)
1313

1414
func TestAccBuildkiteClusterDefaultQueueResource(t *testing.T) {
15-
RegisterResourceTracking(t)
1615
t.Parallel()
1716

1817
t.Run("attach a default queue to a cluster", func(t *testing.T) {

buildkite/resource_cluster_queue_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
)
1515

1616
func TestAccBuildkiteClusterQueueResource(t *testing.T) {
17-
RegisterResourceTracking(t)
1817
configBasic := func(fields ...string) string {
1918
return fmt.Sprintf(`
2019
provider "buildkite" {
@@ -495,9 +494,6 @@ func testAccCheckClusterQueueExists(resourceName string, clusterQueueResourceMod
495494
if resourceState.Primary.ID == "" {
496495
return fmt.Errorf("No ID is set in state")
497496
}
498-
499-
TrackResource("buildkite_cluster_queue", resourceState.Primary.ID)
500-
501497
// Obtain queues of the queue's cluster from its cluster UUID
502498
var matchFound bool
503499
ctx := context.Background()
@@ -580,7 +576,6 @@ func testAccCheckClusterQueueDestroy(s *terraform.State) error {
580576
continue
581577
}
582578

583-
UntrackResource("buildkite_cluster_queue", rs.Primary.ID)
584579
}
585580
return nil
586581
}

buildkite/resource_cluster_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ func testAccCheckClusterExists(name string, c *clusterResourceModel) resource.Te
172172
if rs.Primary.ID == "" {
173173
return fmt.Errorf("No ID is set in state")
174174
}
175-
176-
// Track this cluster for cleanup in case of test failure
177-
TrackResource("buildkite_cluster", rs.Primary.ID)
178-
179175
r, err := getNode(context.Background(), genqlientGraphql, rs.Primary.ID)
180176
if err != nil {
181177
return err
@@ -206,7 +202,6 @@ func testAccCheckClusterDestroy(s *terraform.State) error {
206202
continue
207203
}
208204

209-
UntrackResource("buildkite_cluster", rs.Primary.ID)
210205
}
211206
return nil
212207
}

buildkite/resource_organization_banner_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
)
1212

1313
func TestAccBuildkiteOrganizationBannerResource(t *testing.T) {
14-
RegisterResourceTracking(t)
1514
config := func(name string) string {
1615
return fmt.Sprintf(`
1716
provider "buildkite" {

buildkite/resource_organization_rule_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
)
1414

1515
func TestAccBuildkiteOrganizationRuleResource(t *testing.T) {
16-
RegisterResourceTracking(t)
1716
ruleActions := []string{"trigger_build", "artifacts_read"}
1817

1918
configRequired := func(fields ...string) string {
@@ -2207,9 +2206,6 @@ func testAccCheckOrganizationRuleExists(orr *organizationRuleResourceModel, name
22072206
if rs.Primary.ID == "" {
22082207
return fmt.Errorf("No ID is set in state")
22092208
}
2210-
2211-
TrackResource("buildkite_organization_rule", rs.Primary.ID)
2212-
22132209
r, err := getNode(context.Background(), genqlientGraphql, rs.Primary.ID)
22142210
if err != nil {
22152211
return err
@@ -2261,7 +2257,6 @@ func testAccCheckOrganizationRuleDestroy(s *terraform.State) error {
22612257
r, err := getNode(context.Background(), genqlientGraphql, rs.Primary.ID)
22622258
if err != nil {
22632259
if strings.Contains(err.Error(), "not found") {
2264-
UntrackResource("buildkite_organization_rule", rs.Primary.ID)
22652260
continue
22662261
}
22672262
return fmt.Errorf("error checking if organization rule exists: %v", err)
@@ -2273,7 +2268,6 @@ func testAccCheckOrganizationRuleDestroy(s *terraform.State) error {
22732268
}
22742269
}
22752270

2276-
UntrackResource("buildkite_organization_rule", rs.Primary.ID)
22772271
}
22782272
return nil
22792273
}

buildkite/resource_pipeline_schedule_test.go

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

1414
func TestAccBuildkitePipelineSchedule(t *testing.T) {
15-
RegisterResourceTracking(t)
1615
config := func(name, cronline, label, env string, enabled bool) string {
1716
return fmt.Sprintf(`
1817
provider "buildkite" {
@@ -53,9 +52,6 @@ func TestAccBuildkitePipelineSchedule(t *testing.T) {
5352
loadPipelineSchedule := func(schedule *PipelineScheduleValues) resource.TestCheckFunc {
5453
return func(s *terraform.State) error {
5554
scheduleRes := s.RootModule().Resources["buildkite_pipeline_schedule.pipeline"]
56-
57-
TrackResource("buildkite_pipeline_schedule", scheduleRes.Primary.ID)
58-
5955
resp, err := getPipelineSchedule(context.Background(), genqlientGraphql, scheduleRes.Primary.ID)
6056
if err != nil {
6157
return err
@@ -225,7 +221,6 @@ func testAccCheckPipelineScheduleDestroy(s *terraform.State) error {
225221
continue
226222
}
227223

228-
UntrackResource("buildkite_pipeline_schedule", rs.Primary.ID)
229224
}
230225
return nil
231226
}

0 commit comments

Comments
 (0)