generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 3
/
group_test.go
98 lines (91 loc) · 3.11 KB
/
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
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
package acc_tests
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"regexp"
"testing"
)
func TestAccResourceGroup(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: validateResourceDestroyed("group", "v1/groups"),
Steps: []resource.TestStep{
{
Config: testAccResourceGroupStep1,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("pfptmeta_group.new_group", "id", regexp.MustCompile("^grp-.*$")),
resource.TestCheckResourceAttr("pfptmeta_group.new_group", "name", "group name"),
resource.TestCheckResourceAttr("pfptmeta_group.new_group", "description", "group description"),
resource.TestCheckResourceAttr("pfptmeta_group.new_group", "expression", "tag_name:tag_value OR platform:macOS"),
),
},
{
Config: testAccResourceGroupStep2,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr("pfptmeta_group.new_group", "id", regexp.MustCompile("^grp-.*$")),
resource.TestCheckResourceAttr("pfptmeta_group.new_group", "name", "group name1"),
resource.TestCheckResourceAttr("pfptmeta_group.new_group", "description", "group description1"),
resource.TestCheckResourceAttr("pfptmeta_group.new_group", "expression", ""),
),
},
},
})
}
const testAccResourceGroupStep1 = `
resource "pfptmeta_group" "new_group" {
name = "group name"
description = "group description"
expression = "tag_name:tag_value OR platform:macOS"
}
`
const testAccResourceGroupStep2 = `
resource "pfptmeta_group" "new_group" {
name = "group name1"
description = "group description1"
}
`
func TestAccDataSourceGroup(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{Config: groupResourceForDataSourceTest},
{
Config: groupResourceForDataSourceTest + testAccDataSourceGroup,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.pfptmeta_group.group_by_id", "id", regexp.MustCompile("^grp-.+$"),
),
resource.TestCheckResourceAttr(
"data.pfptmeta_group.group_by_id", "name", "data-source-group",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_group.group_by_id", "description", "Some group description",
),
resource.TestMatchResourceAttr(
"data.pfptmeta_group.group_by_id", "id", regexp.MustCompile("^grp-.+$"),
),
resource.TestCheckResourceAttr(
"data.pfptmeta_group.group_by_name", "name", "data-source-group",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_group.group_by_name", "description", "Some group description",
),
),
},
},
})
}
const groupResourceForDataSourceTest = `
resource "pfptmeta_group" "new_group" {
name = "data-source-group"
description = "Some group description"
}`
const testAccDataSourceGroup = `
data "pfptmeta_group" "group_by_id" {
id = pfptmeta_group.new_group.id
}
data "pfptmeta_group" "group_by_name" {
name = "data-source-group"
}
`