@@ -12,62 +12,83 @@ import (
1212 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1313)
1414
15- func TestAccDbtCloudUserGroupsResource (t * testing.T ) {
15+ var userID = acctest_config .AcceptanceTestConfig .DbtCloudUserId
16+ var groupIDs = fmt .Sprintf ("[%s]" , acctest_config .AcceptanceTestConfig .DbtCloudGroupIds )
17+ var GroupName = acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
18+
19+ var addRoleTestStep = resource.TestStep {
20+ Config : testAccDbtCloudUserGroupsResourceAddRole (userID , GroupName , groupIDs ),
21+ Check : resource .ComposeTestCheckFunc (
22+ resource .TestCheckResourceAttr (
23+ "dbtcloud_user_groups.test_user_groups" ,
24+ "user_id" ,
25+ strconv .Itoa (userID ),
26+ ),
27+ resource .TestCheckResourceAttrSet (
28+ "dbtcloud_user_groups.test_user_groups" ,
29+ "group_ids.0" ,
30+ ),
31+ resource .TestCheckResourceAttrSet (
32+ "dbtcloud_user_groups.test_user_groups" ,
33+ "group_ids.3" ,
34+ ),
35+ ),
36+ }
37+
38+ var removeRoleTestStep = resource.TestStep {
39+ Config : testAccDbtCloudUserGroupsResourceRemoveRole (userID , GroupName , groupIDs ),
40+ Check : resource .ComposeTestCheckFunc (
41+ resource .TestCheckResourceAttr (
42+ "dbtcloud_user_groups.test_user_groups" ,
43+ "user_id" ,
44+ strconv .Itoa (userID ),
45+ ),
46+ resource .TestCheckResourceAttrSet (
47+ "dbtcloud_user_groups.test_user_groups" ,
48+ "group_ids.0" ,
49+ ),
50+ //we should only have 3 groups now that we check that there is no item at index 3 (starts at 0)
51+ // TODO: This test depends on the number of groups defined in the acceptance test config, which is not guaranteed.
52+ resource .TestCheckNoResourceAttr (
53+ "dbtcloud_user_groups.test_user_groups" ,
54+ "group_ids.3" ,
55+ ),
56+ ),
57+ }
1658
17- userID := acctest_config .AcceptanceTestConfig .DbtCloudUserId
18- groupIDs := fmt .Sprintf ("[%s]" , acctest_config .AcceptanceTestConfig .DbtCloudGroupIds )
19- GroupName := acctest .RandStringFromCharSet (10 , acctest .CharSetAlpha )
59+ func TestAccDbtCloudUserGroupsResource (t * testing.T ) {
60+ var importStateTestStep = resource.TestStep {
61+ ResourceName : "dbtcloud_user_groups.test_user_groups" ,
62+ ImportState : true ,
63+ ImportStateVerify : true ,
64+ ImportStateVerifyIgnore : []string {},
65+ }
2066
2167 resource .Test (t , resource.TestCase {
2268 PreCheck : func () { acctest_helper .TestAccPreCheck (t ) },
2369 ProtoV6ProviderFactories : acctest_helper .TestAccProtoV6ProviderFactories ,
2470 Steps : []resource.TestStep {
25- {
26- Config : testAccDbtCloudUserGroupsResourceAddRole (userID , GroupName , groupIDs ),
27- Check : resource .ComposeTestCheckFunc (
28- resource .TestCheckResourceAttr (
29- "dbtcloud_user_groups.test_user_groups" ,
30- "user_id" ,
31- strconv .Itoa (userID ),
32- ),
33- resource .TestCheckResourceAttrSet (
34- "dbtcloud_user_groups.test_user_groups" ,
35- "group_ids.0" ,
36- ),
37- resource .TestCheckResourceAttrSet (
38- "dbtcloud_user_groups.test_user_groups" ,
39- "group_ids.3" ,
40- ),
41- ),
42- },
43- //MODIFY
44- {
45- Config : testAccDbtCloudUserGroupsResourceRemoveRole (userID , GroupName , groupIDs ),
46- Check : resource .ComposeTestCheckFunc (
47- resource .TestCheckResourceAttr (
48- "dbtcloud_user_groups.test_user_groups" ,
49- "user_id" ,
50- strconv .Itoa (userID ),
51- ),
52- resource .TestCheckResourceAttrSet (
53- "dbtcloud_user_groups.test_user_groups" ,
54- "group_ids.0" ,
55- ),
56- //we should only have 3 groups now that we check that there is no item at index 3 (starts at 0)
57- // TODO: This test depends on the number of groups defined in the acceptance test config, which is not guaranteed.
58- resource .TestCheckNoResourceAttr (
59- "dbtcloud_user_groups.test_user_groups" ,
60- "group_ids.3" ,
61- ),
62- ),
63- },
64- // IMPORT
65- {
66- ResourceName : "dbtcloud_user_groups.test_user_groups" ,
67- ImportState : true ,
68- ImportStateVerify : true ,
69- ImportStateVerifyIgnore : []string {},
70- },
71+ addRoleTestStep ,
72+ removeRoleTestStep ,
73+ importStateTestStep ,
74+ },
75+ })
76+ }
77+
78+ func TestConfDbtCloudUserGroupsResource (t * testing.T ) {
79+ resource .Test (t , resource.TestCase {
80+ PreCheck : func () { acctest_helper .TestAccPreCheck (t ) },
81+ Steps : []resource.TestStep {
82+ acctest_helper .MakeExternalProviderTestStep (addRoleTestStep , acctest_config .LAST_VERSION_BEFORE_FRAMEWORK_MIGRATION ),
83+ acctest_helper .MakeCurrentProviderNoOpTestStep (addRoleTestStep ),
84+ },
85+ })
86+
87+ resource .Test (t , resource.TestCase {
88+ PreCheck : func () { acctest_helper .TestAccPreCheck (t ) },
89+ Steps : []resource.TestStep {
90+ acctest_helper .MakeExternalProviderTestStep (removeRoleTestStep , acctest_config .LAST_VERSION_BEFORE_FRAMEWORK_MIGRATION ),
91+ acctest_helper .MakeCurrentProviderNoOpTestStep (removeRoleTestStep ),
7192 },
7293 })
7394}
@@ -117,4 +138,4 @@ resource "dbtcloud_user_groups" "test_user_groups" {
117138 group_ids = %s
118139 }
119140` , groupName , userID , groupIDs )
120- }
141+ }
0 commit comments