-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_openstack_containerinfra_cluster_v1_test.go
More file actions
67 lines (58 loc) · 2.01 KB
/
Copy pathdata_source_openstack_containerinfra_cluster_v1_test.go
File metadata and controls
67 lines (58 loc) · 2.01 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
package openstack
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccContainerInfraV1ClusterDataSource_basic(t *testing.T) {
resourceName := "openstack_containerinfra_cluster_v1.cluster_1"
clusterName := acctest.RandomWithPrefix("tf-acc-cluster")
keypairName := acctest.RandomWithPrefix("tf-acc-keypair")
clusterTemplateName := acctest.RandomWithPrefix("tf-acc-clustertemplate")
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckNonAdminOnly(t)
testAccPreCheckContainerInfra(t)
},
ProviderFactories: testAccProviders,
CheckDestroy: testAccCheckContainerInfraV1ClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerInfraV1ClusterBasic(keypairName, clusterTemplateName, clusterName),
},
{
Config: testAccContainerInfraV1ClusterDataSourceBasic(
testAccContainerInfraV1ClusterBasic(keypairName, clusterTemplateName, clusterName),
),
Check: resource.ComposeTestCheckFunc(
testAccCheckContainerInfraV1ClusterDataSourceID(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", clusterName),
resource.TestCheckResourceAttr(resourceName, "master_count", "1"),
resource.TestCheckResourceAttr(resourceName, "node_count", "1"),
),
},
},
})
}
func testAccCheckContainerInfraV1ClusterDataSourceID(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ct, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Can't find cluster data source: %s", n)
}
if ct.Primary.ID == "" {
return fmt.Errorf("Cluster data source ID is not set")
}
return nil
}
}
func testAccContainerInfraV1ClusterDataSourceBasic(clusterResource string) string {
return fmt.Sprintf(`
%s
data "openstack_containerinfra_cluster_v1" "cluster_1" {
name = "${openstack_containerinfra_cluster_v1.cluster_1.name}"
}
`, clusterResource)
}