-
Notifications
You must be signed in to change notification settings - Fork 0
/
groups_data_source_test.go
66 lines (56 loc) · 1.87 KB
/
groups_data_source_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
package provider
import (
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)
func TestAccGroupsDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Read testing
{
Config: testAccGroupsDataSourceConfig(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.hund_groups.test", "groups.#", "2"),
resource.TestCheckTypeSetElemAttrPair("data.hund_groups.test", "groups.*.id", "hund_group.test0", "id"),
resource.TestCheckTypeSetElemAttrPair("data.hund_groups.test", "groups.*.id", "hund_group.test1", "id"),
resource.TestCheckResourceAttr("data.hund_groups.test", "groups.0.components.#", "1"),
resource.TestCheckTypeSetElemAttrPair("data.hund_groups.test", "groups.*.components.*", "hund_component.test0", "id"),
resource.TestCheckResourceAttr("data.hund_groups.test", "groups.1.components.#", "1"),
resource.TestCheckTypeSetElemAttrPair("data.hund_groups.test", "groups.*.components.*", "hund_component.test1", "id"),
),
},
},
})
}
func testAccGroupsDataSourceConfig_base() string {
return providerConfig + `
resource "hund_group" "test0" {
name = "Test Group 1"
}
resource "hund_group" "test1" {
name = "Test Group 2"
}
resource "hund_component" "test0" {
group = hund_group.test0.id
name = "Test Component"
watchdog = {service = {manual = {}}}
}
resource "hund_component" "test1" {
group = hund_group.test1.id
name = "Test Component"
watchdog = {service = {manual = {}}}
}
`
}
func testAccGroupsDataSourceConfig() string {
return testAccGroupsDataSourceConfig_base() + `
data "hund_groups" "test" {
depends_on = [
hund_component.test0,
hund_component.test1
]
}
`
}