Repository navigation
Expand file tree
/
Copy pathdata_source_openstack_containerinfra_nodegroup_v1_test.go
More file actions
68 lines (59 loc) · 2.14 KB
/
Copy pathdata_source_openstack_containerinfra_nodegroup_v1_test.go
File metadata and controls
68 lines (59 loc) · 2.14 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
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 TestAccContainerInfraV1NodeGroupDataSource_basic(t *testing.T) {
resourceName := "openstack_containerinfra_nodegroup_v1.nodegroup_1"
nodeGroupName := acctest.RandomWithPrefix("tf-acc-nodegroup")
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: testAccContainerInfraV1NodeGroupUpdate(keypairName, clusterTemplateName, clusterName, nodeGroupName, 1),
},
{
Config: testAccContainerInfraV1NodeGroupDataSourceBasic(
testAccContainerInfraV1NodeGroupUpdate(keypairName, clusterTemplateName, clusterName, nodeGroupName, 1),
),
Check: resource.ComposeTestCheckFunc(
testAccCheckContainerInfraV1NodeGroupDataSourceID(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", nodeGroupName),
resource.TestCheckResourceAttr(resourceName, "node_count", "1"),
),
},
},
})
}
func testAccCheckContainerInfraV1NodeGroupDataSourceID(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 testAccContainerInfraV1NodeGroupDataSourceBasic(nodeGroupResource string) string {
return fmt.Sprintf(`
%s
data "openstack_containerinfra_nodegroup_v1" "nodegroup_1" {
cluster_id = "${openstack_containerinfra_cluster_v1.cluster_1.name}"
name = "${openstack_containerinfra_nodegroup_v1.nodegroup_1.name}"
}
`, nodeGroupResource)
}