@@ -12,6 +12,8 @@ import (
12
12
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
13
13
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
14
14
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
15
+
16
+ testhelper "gitlab.eng.vmware.com/olympus/terraform-provider-tanzu/internal/resources/testing"
15
17
)
16
18
17
19
func TestAcceptanceForClusterGroupDataSource (t * testing.T ) {
@@ -22,21 +24,14 @@ func TestAcceptanceForClusterGroupDataSource(t *testing.T) {
22
24
resourceName := "tmc_cluster_group.test_cluster_group"
23
25
24
26
resource .Test (t , resource.TestCase {
25
- PreCheck : testPreCheck (t ),
26
- ProviderFactories : getTestProviderFactories (provider ),
27
+ PreCheck : testhelper . TestPreCheck (t ),
28
+ ProviderFactories : testhelper . GetTestProviderFactories (provider ),
27
29
CheckDestroy : nil ,
28
30
Steps : []resource.TestStep {
29
31
{
30
- Config : getTestDataSourceClusterGroupConfigValue (clusterGroup ),
32
+ Config : getTestDataSourceClusterGroupConfigValue (clusterGroup , testhelper . MetaTemplate ),
31
33
Check : resource .ComposeTestCheckFunc (
32
- verifyClusterGroupDataSource (dataSourceName ),
33
- resource .TestCheckResourceAttrPair (dataSourceName , "name" , resourceName , "name" ),
34
- resource .TestCheckResourceAttrPair (dataSourceName , "meta.0.description" , resourceName , "meta.0.description" ),
35
- resource .TestCheckResourceAttrPair (dataSourceName , "meta.0.labels.key1" , resourceName , "meta.0.labels.key1" ),
36
- resource .TestCheckResourceAttrPair (dataSourceName , "meta.0.labels.key2" , resourceName , "meta.0.labels.key2" ),
37
- resource .TestCheckResourceAttrSet (dataSourceName , "id" ),
38
- resource .TestCheckResourceAttrSet (dataSourceName , "meta.0.annotations.authoritativeRID" ),
39
- resource .TestCheckResourceAttrSet (dataSourceName , "meta.0.uid" ),
34
+ checkDataSourceAttributes (dataSourceName , resourceName ),
40
35
),
41
36
},
42
37
},
@@ -45,30 +40,36 @@ func TestAcceptanceForClusterGroupDataSource(t *testing.T) {
45
40
t .Log ("cluster group data source acceptance test complete!" )
46
41
}
47
42
48
- func getTestDataSourceClusterGroupConfigValue (clusterGroupName string ) string {
43
+ func getTestDataSourceClusterGroupConfigValue (clusterGroupName , meta string ) string {
49
44
return fmt .Sprintf (`
50
45
resource "tmc_cluster_group" "test_cluster_group" {
51
46
name = "%s"
52
- meta {
53
- description = "cluster group with description"
54
- labels = {
55
- "key1" : "value1"
56
- "key2" : "value2"
57
- }
58
- }
47
+ %s
59
48
}
60
49
61
50
data "tmc_cluster_group" "test_data_cluster_group" {
62
51
name = tmc_cluster_group.test_cluster_group.name
63
52
}
64
- ` , clusterGroupName )
53
+ ` , clusterGroupName , meta )
54
+ }
55
+
56
+ func checkDataSourceAttributes (dataSourceName , resourceName string ) resource.TestCheckFunc {
57
+ var check = []resource.TestCheckFunc {
58
+ verifyClusterGroupDataSource (dataSourceName ),
59
+ resource .TestCheckResourceAttrPair (dataSourceName , "name" , resourceName , "name" ),
60
+ resource .TestCheckResourceAttrSet (dataSourceName , "id" ),
61
+ }
62
+
63
+ check = append (check , testhelper .MetaDataSourceAttributeCheck (dataSourceName , resourceName )... )
64
+
65
+ return resource .ComposeTestCheckFunc (check ... )
65
66
}
66
67
67
68
func verifyClusterGroupDataSource (name string ) resource.TestCheckFunc {
68
69
return func (s * terraform.State ) error {
69
70
_ , ok := s .RootModule ().Resources [name ]
70
71
if ! ok {
71
- return fmt .Errorf ("root module has cluster group resource %s" , name )
72
+ return fmt .Errorf ("root module does not have cluster group resource %s" , name )
72
73
}
73
74
74
75
return nil
0 commit comments