-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathdata_source_credential_test.go
More file actions
99 lines (82 loc) · 2.75 KB
/
Copy pathdata_source_credential_test.go
File metadata and controls
99 lines (82 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//go:build credential
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: MPL-2.0
package credential
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
testhelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/testing"
)
func TestAcceptanceForClusterGroupDataSource(t *testing.T) {
var provider = initTestProvider(t)
cred := acctest.RandomWithPrefix("tf-cred-test")
dataSourceName := fmt.Sprintf("data.%s.%s", credentialResource, credentialDataSourceVar)
resourceName := fmt.Sprintf("%s.%s", credentialResource, credentialResourceVar)
resource.Test(t, resource.TestCase{
PreCheck: testhelper.TestPreCheck(t),
ProviderFactories: testhelper.GetTestProviderFactories(provider),
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: getTestDataSourceCredConfigValue(cred, testhelper.MetaTemplate),
Check: resource.ComposeTestCheckFunc(
checkDataSourceAttributes(dataSourceName, resourceName),
),
},
},
},
)
t.Log("credential data source acceptance test complete!")
}
func getTestDataSourceCredConfigValue(credName, meta string) string {
return fmt.Sprintf(`
resource "%s" "%s" {
name = "%s"
%s
spec {
capability = "MANAGED_K8S_PROVIDER"
provider = "AWS_EKS"
data {
aws_credential {
account_id = ""
generic_credential = ""
iam_role{
arn = "arn:aws:iam::4987398738934:role/clusterlifecycle-test.tmc.cloud.vmware.com"
ext_id =""
}
}
}
}
}
data "%s" "%s" {
name = tanzu-mission-control_credential.test_credential.name
}
`, credentialResource, credentialResourceVar, credName, meta, credentialResource, credentialDataSourceVar)
}
func checkDataSourceAttributes(dataSourceName, resourceName string) resource.TestCheckFunc {
checks := []resource.TestCheckFunc{
resource.TestCheckResourceAttr(resourceName, "meta.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "meta.0.uid"),
}
check := make([]resource.TestCheckFunc, 0, 3+len(checks))
check = append(check,
verifyClusterGroupDataSource(dataSourceName),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrSet(dataSourceName, "id"),
)
check = append(check, checks...)
return resource.ComposeTestCheckFunc(check...)
}
func verifyClusterGroupDataSource(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
_, ok := s.RootModule().Resources[name]
if !ok {
return fmt.Errorf("root module does not have credential resource %s", name)
}
return nil
}
}