forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_vsphere_resource_pool_test.go
158 lines (141 loc) · 3.88 KB
/
data_source_vsphere_resource_pool_test.go
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package vsphere
import (
"fmt"
"os"
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)
func TestAccDataSourceVSphereResourcePool_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccDataSourceVSphereResourcePoolPreCheck(t)
testAccSkipIfEsxi(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereResourcePoolConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("data.vsphere_resource_pool.pool", "id", regexp.MustCompile("^resgroup-")),
),
},
},
})
}
func TestAccDataSourceVSphereResourcePool_noDatacenterAndAbsolutePath(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccDataSourceVSphereResourcePoolPreCheck(t)
testAccSkipIfEsxi(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereResourcePoolConfigAbsolutePath(),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("data.vsphere_resource_pool.pool", "id", regexp.MustCompile("^resgroup-")),
),
},
},
})
}
func TestAccDataSourceVSphereResourcePool_defaultResourcePoolForESXi(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccDataSourceVSphereResourcePoolPreCheck(t)
testAccSkipIfNotEsxi(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereResourcePoolConfigDefault,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("data.vsphere_resource_pool.pool", "id", regexp.MustCompile("^ha-root-pool$")),
),
},
},
})
}
func TestAccDataSourceVSphereResourcePool_emptyNameOnVCenterShouldError(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccDataSourceVSphereResourcePoolPreCheck(t)
testAccSkipIfEsxi(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceVSphereResourcePoolConfigDefault,
ExpectError: regexp.MustCompile("name cannot be empty when using vCenter"),
PlanOnly: true,
},
{
Config: testAccResourceVSphereEmpty,
Check: resource.ComposeTestCheckFunc(),
},
},
})
}
func testAccDataSourceVSphereResourcePoolPreCheck(t *testing.T) {
if os.Getenv("VSPHERE_DATACENTER") == "" {
t.Skip("set VSPHERE_DATACENTER to run vsphere_resource_pool data source acceptance tests")
}
if os.Getenv("VSPHERE_CLUSTER") == "" {
t.Skip("set VSPHERE_CLUSTER to run vsphere_resource_pool data source acceptance tests")
}
if os.Getenv("VSPHERE_RESOURCE_POOL") == "" {
t.Skip("set VSPHERE_RESOURCE_POOL to run vsphere_resource_pool data source acceptance tests")
}
}
func testAccDataSourceVSphereResourcePoolConfig() string {
return fmt.Sprintf(`
variable "datacenter" {
default = "%s"
}
variable "cluster" {
default = "%s"
}
variable "resource_pool" {
default = "%s"
}
data "vsphere_datacenter" "dc" {
name = "${var.datacenter}"
}
data "vsphere_resource_pool" "pool" {
name = "${var.cluster}/Resources/${var.resource_pool}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
`,
os.Getenv("VSPHERE_DATACENTER"),
os.Getenv("VSPHERE_CLUSTER"),
os.Getenv("VSPHERE_RESOURCE_POOL"),
)
}
func testAccDataSourceVSphereResourcePoolConfigAbsolutePath() string {
return fmt.Sprintf(`
variable "datacenter" {
default = "%s"
}
variable "cluster" {
default = "%s"
}
variable "resource_pool" {
default = "%s"
}
data "vsphere_resource_pool" "pool" {
name = "/${var.datacenter}/host/${var.cluster}/Resources/${var.resource_pool}"
}
`,
os.Getenv("VSPHERE_DATACENTER"),
os.Getenv("VSPHERE_CLUSTER"),
os.Getenv("VSPHERE_RESOURCE_POOL"),
)
}
const testAccDataSourceVSphereResourcePoolConfigDefault = `
data "vsphere_resource_pool" "pool" {}
`