generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 3
/
policy_test.go
137 lines (123 loc) · 3.92 KB
/
policy_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
package acc_tests
import (
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccResourcePolicy(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: validateResourceDestroyed("policy", "v1/policies"),
Steps: []resource.TestStep{
{
Config: testAccPolicyStep1,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"pfptmeta_policy.policy", "id", regexp.MustCompile("^pol-.+$"),
),
resource.TestCheckResourceAttr(
"pfptmeta_policy.policy", "name", "policy name",
),
resource.TestCheckResourceAttr(
"pfptmeta_policy.policy", "description", "policy description",
),
resource.TestCheckTypeSetElemAttrPair(
"pfptmeta_policy.policy", "sources.*", "pfptmeta_group.group", "id",
),
resource.TestCheckTypeSetElemAttrPair(
"pfptmeta_policy.policy", "destinations.*", "pfptmeta_network_element.mapped-service", "id",
),
resource.TestCheckTypeSetElemAttrPair(
"pfptmeta_policy.policy", "protocol_groups.0", "data.pfptmeta_protocol_group.HTTPS", "id",
),
),
},
{
Config: testAccPolicyStep2,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"pfptmeta_policy.policy", "name", "policy name1",
),
resource.TestCheckResourceAttr(
"pfptmeta_policy.policy", "description", "policy description1",
),
resource.TestCheckResourceAttr("pfptmeta_policy.policy", "sources.#", "0"),
resource.TestCheckResourceAttr("pfptmeta_policy.policy", "destinations.#", "0"),
resource.TestCheckResourceAttr("pfptmeta_policy.policy", "protocol_groups.#", "0"),
),
},
},
})
}
func TestAccDataSourcePolicy(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: validateResourceDestroyed("policy", "v1/policies"),
Steps: []resource.TestStep{
{
Config: testAccPolicyStep1 + policyDataSource,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.pfptmeta_policy.policy", "id", regexp.MustCompile("^pol-.+$"),
),
resource.TestCheckResourceAttr(
"data.pfptmeta_policy.policy", "name", "policy name",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_policy.policy", "description", "policy description",
),
resource.TestMatchResourceAttr(
"data.pfptmeta_policy.policy", "sources.0", regexp.MustCompile("^grp-.+$"),
),
resource.TestMatchResourceAttr(
"data.pfptmeta_policy.policy", "destinations.0", regexp.MustCompile("^ne-[\\d]+$"),
),
resource.TestMatchResourceAttr(
"data.pfptmeta_policy.policy", "protocol_groups.0", regexp.MustCompile("^pg-.+$"),
),
),
},
},
})
}
const testAccPolicyStep1 = `
resource "pfptmeta_group" "group" {
name = "policy-test-group"
}
data "pfptmeta_protocol_group" "HTTPS" {
name = "HTTPS"
}
resource "pfptmeta_network_element" "mapped-service" {
name = "mapped service"
mapped_service = "mapped.service.com"
}
resource "pfptmeta_policy" "policy" {
name = "policy name"
description = "policy description"
sources = [pfptmeta_group.group.id]
destinations = [pfptmeta_network_element.mapped-service.id]
protocol_groups = [data.pfptmeta_protocol_group.HTTPS.id]
}
`
const testAccPolicyStep2 = `
resource "pfptmeta_group" "group" {
name = "policy-test-group"
}
data "pfptmeta_protocol_group" "HTTPS" {
name = "HTTPS"
}
resource "pfptmeta_network_element" "mapped-service" {
name = "mapped service"
mapped_service = "mapped.service.com"
}
resource "pfptmeta_policy" "policy" {
name = "policy name1"
description = "policy description1"
}
`
const policyDataSource = `
data "pfptmeta_policy" "policy" {
id = pfptmeta_policy.policy.id
}`