-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstructure_role_test.go
116 lines (110 loc) · 2.6 KB
/
structure_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
package main
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
reflect "reflect"
"testing"
)
var (
testRoleConf *Role
testRoleInterface map[string]interface{}
)
func init() {
TRUE := true
FALSE := false
testRoleConf = &Role{
Description: "test description",
Enabled: &TRUE,
Name: "test name",
RoleOwner: &ObjectInfo{
ID: "2c9180887412345678948078d29f2e46",
Name: "SRE Test",
Type: "IDENTITY",
},
AccessProfiles: []*ObjectInfo{
{
ID: "2c918088747654398948078d29f2e46",
Name: "Test Developer",
Type: "ACCESS_PROFILE",
},
{
ID: "2c918009437654398948078d29f2e46",
Name: "Test Operator",
Type: "ACCESS_PROFILE",
},
},
Requestable: &FALSE,
}
testRoleInterface = map[string]interface{}{
"access_profiles": []interface{}{
map[string]interface{}{
"id": "2c918088747654398948078d29f2e46",
"name": "Test Developer",
"type": "ACCESS_PROFILE",
},
map[string]interface{}{
"id": "2c918009437654398948078d29f2e46",
"name": "Test Operator",
"type": "ACCESS_PROFILE",
},
},
"owner": []interface{}{
map[string]interface{}{
"id": "2c9180887412345678948078d29f2e46",
"name": "SRE Test",
"type": "IDENTITY",
},
},
"description": "test description",
"enabled": true,
"name": "test name",
"requestable": false,
}
}
func TestFlattenRole(t *testing.T) {
cases := []struct {
Input *Role
ExpectedOutput map[string]interface{}
}{
{
testRoleConf,
testRoleInterface,
},
}
for _, tc := range cases {
output := schema.TestResourceDataRaw(t, roleFields(), tc.ExpectedOutput)
err := flattenRole(output, tc.Input)
if err != nil {
t.Fatalf("[ERROR] on flattener: %#v", err)
}
expectedOutput := map[string]interface{}{}
for k := range tc.ExpectedOutput {
expectedOutput[k] = output.Get(k)
}
if !reflect.DeepEqual(expectedOutput, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from flattener.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, expectedOutput)
}
}
}
func TestExpandRole(t *testing.T) {
cases := []struct {
Input map[string]interface{}
ExpectedOutput *Role
}{
{
testRoleInterface,
testRoleConf,
},
}
for _, tc := range cases {
inputResourceData := schema.TestResourceDataRaw(t, roleFields(), tc.Input)
output, err := expandRole(inputResourceData)
if err != nil {
t.Fatalf("[ERROR] on flattener: %#v", err)
}
if !reflect.DeepEqual(output, tc.ExpectedOutput) {
t.Fatalf("Unexpected output from expander.\nExpected: %#v\nGiven: %#v",
tc.ExpectedOutput, output)
}
}
}