-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_openstack_compute_aggregate_v2_test.go
More file actions
117 lines (104 loc) · 3.02 KB
/
Copy pathdata_source_openstack_compute_aggregate_v2_test.go
File metadata and controls
117 lines (104 loc) · 3.02 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package openstack
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
const testAccAggregateResource = `
resource "openstack_compute_aggregate_v2" "test2" {
name = "test2"
zone = "nova"
metadata = {
"test" = "test123"
}
}
`
const testAccAggregateDataSource = `
data "openstack_compute_aggregate_v2" "test2" {
name = openstack_compute_aggregate_v2.test2.name
}
resource "openstack_compute_aggregate_v2" "test2" {
name = "test2"
zone = "nova"
metadata = {
"test" = "test123"
}
}
`
func TestAccAggregateDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckAdminOnly(t) },
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAggregateResource,
},
{
Config: testAccAggregateDataSource,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeAggregateV2DataSourceID("data.openstack_compute_aggregate_v2.test2"),
resource.TestCheckResourceAttr("data.openstack_compute_aggregate_v2.test2", "name", "test2"),
resource.TestCheckResourceAttr("data.openstack_compute_aggregate_v2.test2", "zone", "nova"),
resource.TestCheckResourceAttr("data.openstack_compute_aggregate_v2.test2", "metadata.test", "test123"),
),
},
},
})
}
func testAccAggregateResourceWithHypervisor() string {
return fmt.Sprintf(`
resource "openstack_compute_aggregate_v2" "test3" {
name = "test3"
zone = "nova"
hosts = ["%s"]
}
`, osHypervisorEnvironment)
}
func testAccAggregateDataSourceWithHypervisor() string {
return fmt.Sprintf(`
data "openstack_compute_aggregate_v2" "test3" {
name = openstack_compute_aggregate_v2.test3.name
}
resource "openstack_compute_aggregate_v2" "test3" {
name = "test3"
zone = "nova"
hosts = ["%s"]
}
`, osHypervisorEnvironment)
}
func TestAccAggregateDataSourceWithHypervisor(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckAdminOnly(t)
testAccPreCheckHypervisor(t)
},
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAggregateResourceWithHypervisor(),
},
{
Config: testAccAggregateDataSourceWithHypervisor(),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeAggregateV2DataSourceID("data.openstack_compute_aggregate_v2.test3"),
resource.TestCheckResourceAttr("data.openstack_compute_aggregate_v2.test3", "name", "test3"),
resource.TestCheckResourceAttr("data.openstack_compute_aggregate_v2.test3", "zone", "nova"),
resource.TestCheckResourceAttr("data.openstack_compute_aggregate_v2.test3", "hosts.#", "1"),
),
},
},
})
}
func testAccCheckComputeAggregateV2DataSourceID(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Can't find data source: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("Data source ID not set")
}
return nil
}
}