-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathresource_inventory_group_test.go
60 lines (51 loc) · 1.36 KB
/
resource_inventory_group_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
package awx
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
// awx_example test case
func TestAccAWXInventoryGroup(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { TestAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccInventoryGroupConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckStateGroup("name", "testacc-grp_1"),
testAccCheckStateGroup("description", "AWX Acc test group"),
),
},
},
})
}
func testAccCheckStateGroup(skey, svalue string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources["awx_inventory_group.testacc-grp"]
if !ok {
return fmt.Errorf("awx_inventory_group.testacc-grp not found")
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
cr := rs.Primary
if cr.Attributes[skey] != svalue {
return fmt.Errorf("%s != %s (actual: %s)", skey, svalue, cr.Attributes[skey])
}
return nil
}
}
const testAccInventoryGroupConfig = `
resource "awx_inventory" "testacc" {
name = "testacc-grp"
organization_id = 1
description = "AWX Acc test"
}
resource "awx_inventory_group" "testacc-grp" {
name = "testacc-grp_1"
inventory_id = "${awx_inventory.testacc.id}"
description = "AWX Acc test group"
}
`