generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 3
/
role_test.go
145 lines (137 loc) · 4.22 KB
/
role_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
138
139
140
141
142
143
144
145
package acc_tests
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"regexp"
"testing"
)
func TestAccResourceRole(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: validateResourceDestroyed("role", "v1/roles"),
Steps: []resource.TestStep{
{
Config: testAccResourceRoleStep1,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"pfptmeta_role.admin_role", "id", regexp.MustCompile("^rol-.*$"),
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "name", "admin role",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "description", "role with all privileges",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "all_read_privileges", "true",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "all_write_privileges", "true",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "all_suborgs", "false",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.with_privileges", "name", "with privs",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.with_privileges", "privileges.0", "metaports:read",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.with_privileges", "privileges.1", "metaports:write",
),
),
},
{
Config: testAccResourceRoleStep2,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"pfptmeta_role.admin_role", "id", regexp.MustCompile("^rol-.*$"),
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "name", "admin role1",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "description", "role with all privileges1",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "all_read_privileges", "false",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "all_write_privileges", "false",
),
resource.TestCheckResourceAttr(
"pfptmeta_role.admin_role", "all_suborgs", "false",
),
),
},
},
})
}
const testAccResourceRoleStep1 = `
resource "pfptmeta_role" "admin_role" {
name = "admin role"
description = "role with all privileges"
apply_to_orgs = ["org-31126"]
all_read_privileges = true
all_write_privileges = true
}
resource "pfptmeta_role" "with_privileges" {
name = "with privs"
apply_to_orgs = ["org-31126"]
privileges = ["metaports:read", "metaports:write"]
}
`
const testAccResourceRoleStep2 = `
resource "pfptmeta_role" "admin_role" {
name = "admin role1"
description = "role with all privileges1"
apply_to_orgs = ["org-31126"]
all_read_privileges = false
}
`
func TestAccDataSourceRole(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceRole,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.pfptmeta_role.admin_by_id", "name", "admin",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_role.admin_by_id", "all_suborgs", "true",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_role.admin_by_id", "all_write_privileges", "true",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_role.admin_by_id", "all_read_privileges", "true",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_role.admin_by_name", "id", "rol-Xqrzun95v8RA59E",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_role.admin_by_name", "all_suborgs", "true",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_role.admin_by_name", "all_write_privileges", "true",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_role.admin_by_name", "all_read_privileges", "true",
),
),
},
},
})
}
const testAccDataSourceRole = `
data "pfptmeta_role" "admin_by_id" {
id = "rol-Xqrzun95v8RA59E"
}
data "pfptmeta_role" "admin_by_name" {
name = "admin"
}
`