-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_openstack_compute_hypervisor_v2_test.go
More file actions
51 lines (44 loc) · 1.23 KB
/
Copy pathdata_source_openstack_compute_hypervisor_v2_test.go
File metadata and controls
51 lines (44 loc) · 1.23 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
package openstack
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func testAccHypervisorDataSource() string {
return fmt.Sprintf(`
data "openstack_compute_hypervisor_v2" "host01" {
hostname = "%s"
}
`, osHypervisorEnvironment)
}
func TestAccComputeHypervisorV2DataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckAdminOnly(t)
testAccPreCheckHypervisor(t)
},
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccHypervisorDataSource(),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeHypervisorV2DataSourceID("data.openstack_compute_hypervisor_v2.host01"),
resource.TestCheckResourceAttr("data.openstack_compute_hypervisor_v2.host01", "hostname", osHypervisorEnvironment),
),
},
},
})
}
func testAccCheckComputeHypervisorV2DataSourceID(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
}
}