-
Notifications
You must be signed in to change notification settings - Fork 7
/
structure_access_profile_test.go
125 lines (119 loc) · 3.04 KB
/
structure_access_profile_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
package main
import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"reflect"
"testing"
)
var (
testAccessProfileConf *AccessProfile
testAccessProfileInterface map[string]interface{}
)
func init() {
FALSE := false
testAccessProfileConf = &AccessProfile{
Name: "test name",
Description: "test Description",
AccessProfileOwner: &ObjectInfo{
ID: "2c9180887412345678948078d29f2e46",
Name: "SRE Test",
Type: "IDENTITY",
},
AccessProfileSource: &ObjectInfo{
ID: "2c91808374bc866a0178948078d29f2e46",
Name: "Product platform, Azure portal, AzureUSGovernment",
Type: "SOURCE",
},
Entitlements: []*ObjectInfo{
{
ID: "2c918088747654398948078d29f2e46",
Name: "Operators_AG1",
Type: "ENTITLEMENT",
},
{
ID: "2c918009437654398948078d29f2e46",
Name: "Integrator_AG1",
Type: "ENTITLEMENT",
},
},
Enabled: &FALSE,
}
testAccessProfileInterface = map[string]interface{}{
"name": "test name",
"description": "test Description",
"source": []interface{}{
map[string]interface{}{
"id": "2c91808374bc866a0178948078d29f2e46",
"name": "Product platform, Azure portal, AzureUSGovernment",
"type": "SOURCE",
},
},
"owner": []interface{}{
map[string]interface{}{
"id": "2c9180887412345678948078d29f2e46",
"name": "SRE Test",
"type": "IDENTITY",
},
},
"entitlements": []interface{}{
map[string]interface{}{
"id": "2c918088747654398948078d29f2e46",
"name": "Operators_AG1",
"type": "ENTITLEMENT",
},
map[string]interface{}{
"id": "2c918009437654398948078d29f2e46",
"name": "Integrator_AG1",
"type": "ENTITLEMENT",
},
},
"enabled": false,
}
}
func TestFlattenAccessProfile(t *testing.T) {
cases := []struct {
Input *AccessProfile
ExpectedOutput map[string]interface{}
}{
{
testAccessProfileConf,
testAccessProfileInterface,
},
}
for _, tc := range cases {
output := schema.TestResourceDataRaw(t, accessProfileFields(), tc.ExpectedOutput)
err := flattenAccessProfile(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 TestExpandAccessProfile(t *testing.T) {
cases := []struct {
Input map[string]interface{}
ExpectedOutput *AccessProfile
}{
{
testAccessProfileInterface,
testAccessProfileConf,
},
}
for _, tc := range cases {
inputResourceData := schema.TestResourceDataRaw(t, accessProfileFields(), tc.Input)
output, err := expandAccessProfile(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)
}
}
}