-
Notifications
You must be signed in to change notification settings - Fork 64
/
policy_group_test.go
140 lines (106 loc) · 2.75 KB
/
policy_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
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
package chef
import (
"fmt"
"net/http"
"os"
"testing"
)
const policyGroupResponseFile = "test/policy_group_response.json"
const policyGroupFile = "test/policy_group.json"
const revisionDetailsResponseFile = "test/revision_details_response.json"
func TestPolicyGroupList(t *testing.T) {
setup()
defer teardown()
file, err := os.ReadFile(policyGroupResponseFile)
if err != nil {
t.Error(err)
}
mux.HandleFunc("/policy_groups", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(file))
})
data, err := client.PolicyGroups.List()
if err != nil {
t.Error(err)
}
if data == nil {
t.Fatal("We should have some data")
}
if len(data) != 1 {
t.Error("Mismatch in expected policy group count. Expected 1, Got: ", len(data))
}
if _, ok := data["demo_policy_group"]; !ok {
t.Error("demo_policy_group policy should be listed")
}
}
func TestPolicyGroupGet(t *testing.T) {
setup()
defer teardown()
file, err := os.ReadFile(policyGroupFile)
if err != nil {
t.Error(err)
}
mux.HandleFunc("/policy_groups/testgroup", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(file))
})
data, err := client.PolicyGroups.Get("testgroup")
if err != nil {
t.Error(err)
}
if _, ok := data.Policies["testsamp"]; !ok {
t.Error("testsamp policy should be listed")
}
}
func TestPolicyGroupDelete(t *testing.T) {
setup()
defer teardown()
file, err := os.ReadFile(policyGroupFile)
if err != nil {
t.Error(err)
}
mux.HandleFunc("/policy_groups/testgroup", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(file))
})
data, err := client.PolicyGroups.Delete("testgroup")
if err != nil {
t.Error(err)
}
if _, ok := data.Policies["testsamp"]; !ok {
t.Error("testsamp policy should be listed")
}
}
func TestPolicyGroupGetPolicy(t *testing.T) {
setup()
defer teardown()
file, err := os.ReadFile(revisionDetailsResponseFile)
if err != nil {
t.Error(err)
}
mux.HandleFunc("/policy_groups/testgroup/policies/testsamp", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(file))
})
data, err := client.PolicyGroups.GetPolicy("testgroup", "testsamp")
if err != nil {
t.Error(err)
}
if data.Name != "testsamp" {
t.Error("testsamp policy should be retrieved")
}
}
func TestPolicyGroupDeletePolicy(t *testing.T) {
setup()
defer teardown()
file, err := os.ReadFile(revisionDetailsResponseFile)
if err != nil {
t.Error(err)
}
mux.HandleFunc("/policy_groups/testgroup/policies/testsamp", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, string(file))
})
data, err := client.PolicyGroups.DeletePolicy("testgroup", "testsamp")
if err != nil {
t.Error(err)
}
if data.Name != "testsamp" {
t.Error("testsamp policy should be retrieved")
}
}