@@ -18,26 +18,38 @@ import (
18
18
)
19
19
20
20
func TestAcc_Resource (t * testing.T ) {
21
- workspaceName := utils .GenerateTestResourceName (10 )
21
+ namePrefix := utils .GenerateTestResourceName (10 )
22
+ workspace1Name := fmt .Sprintf ("%v-1" , namePrefix )
23
+ workspace2Name := fmt .Sprintf ("%v-2" , namePrefix )
24
+
22
25
resource .Test (t , resource.TestCase {
23
26
ProtoV6ProviderFactories : astronomerprovider .TestAccProtoV6ProviderFactories ,
24
27
PreCheck : func () { astronomerprovider .TestAccPreCheck (t ) },
28
+ CheckDestroy : resource .ComposeTestCheckFunc (
29
+ // Check that workspaces have been removed
30
+ testAccCheckWorkspaceExistence (t , workspace1Name , false ),
31
+ testAccCheckWorkspaceExistence (t , workspace2Name , false ),
32
+ ),
25
33
Steps : []resource.TestStep {
26
34
{
27
- Config : astronomerprovider .ProviderConfig () + workspace (fmt . Sprintf ( "%v-1" , workspaceName ) , "test" , false ),
35
+ Config : astronomerprovider .ProviderConfig () + workspace (workspace1Name , "test" , false ),
28
36
Check : resource .ComposeTestCheckFunc (
29
- resource .TestCheckResourceAttr ("astronomer_workspace.test" , "name" , fmt . Sprintf ( "%v-1" , workspaceName ) ),
37
+ resource .TestCheckResourceAttr ("astronomer_workspace.test" , "name" , workspace1Name ),
30
38
resource .TestCheckResourceAttr ("astronomer_workspace.test" , "description" , "test" ),
31
39
resource .TestCheckResourceAttr ("astronomer_workspace.test" , "cicd_enforced_default" , "false" ),
40
+ // Check via API that workspace exists
41
+ testAccCheckWorkspaceExistence (t , workspace1Name , true ),
32
42
),
33
43
},
34
44
// Change properties and check they have been updated in terraform state
35
45
{
36
- Config : astronomerprovider .ProviderConfig () + workspace (fmt . Sprintf ( "%v-2" , workspaceName ) , utils .TestResourceDescription , true ),
46
+ Config : astronomerprovider .ProviderConfig () + workspace (workspace2Name , utils .TestResourceDescription , true ),
37
47
Check : resource .ComposeTestCheckFunc (
38
- resource .TestCheckResourceAttr ("astronomer_workspace.test" , "name" , fmt . Sprintf ( "%v-2" , workspaceName ) ),
48
+ resource .TestCheckResourceAttr ("astronomer_workspace.test" , "name" , workspace2Name ),
39
49
resource .TestCheckResourceAttr ("astronomer_workspace.test" , "description" , utils .TestResourceDescription ),
40
50
resource .TestCheckResourceAttr ("astronomer_workspace.test" , "cicd_enforced_default" , "true" ),
51
+ // Check via API that workspace exists
52
+ testAccCheckWorkspaceExistence (t , workspace2Name , true ),
41
53
),
42
54
},
43
55
// Import existing workspace and check it is correctly imported - https://stackoverflow.com/questions/68824711/how-can-i-test-terraform-import-in-acceptance-tests
@@ -68,6 +80,7 @@ func TestAcc_WorkspaceRemovedOutsideOfTerraform(t *testing.T) {
68
80
Check : resource .ComposeTestCheckFunc (
69
81
resource .TestCheckResourceAttr ("astronomer_workspace.test" , "name" , workspaceName ),
70
82
resource .TestCheckResourceAttr ("astronomer_workspace.test" , "description" , utils .TestResourceDescription ),
83
+ // Check via API that workspace exists
71
84
testAccCheckWorkspaceExistence (t , workspaceName , true ),
72
85
),
73
86
},
@@ -83,6 +96,7 @@ func TestAcc_WorkspaceRemovedOutsideOfTerraform(t *testing.T) {
83
96
Check : resource .ComposeTestCheckFunc (
84
97
resource .TestCheckResourceAttr ("astronomer_workspace.test" , "name" , workspaceName ),
85
98
resource .TestCheckResourceAttr ("astronomer_workspace.test" , "description" , utils .TestResourceDescription ),
99
+ // Check via API that workspace exists
86
100
testAccCheckWorkspaceExistence (t , workspaceName , true ),
87
101
),
88
102
},
0 commit comments