-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
74 lines (69 loc) · 1.51 KB
/
main_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
package main
import (
"encoding/json"
"testing"
)
func TestPermissionList(t *testing.T) {
tests := []struct {
Input string
Output Permissions
Error string
}{
{
Input: `{}`,
Output: Permissions{
Read: true,
Write: false,
Delete: false,
},
},
{
Input: `{"read": true, "write": true, "delete": true}`,
Output: Permissions{
Read: true,
Write: true,
Delete: true,
},
},
{
Input: `{"read": false, "write": false, "delete": false}`,
Output: Permissions{
Read: false,
Write: false,
Delete: false,
},
},
{
Input: `{"delete": true}`,
Output: Permissions{
Read: true,
Write: false,
Delete: true,
},
},
}
for _, tt := range tests {
t.Run(tt.Input, func(t *testing.T) {
var conf Configuration
if err := json.Unmarshal([]byte(`{"apps":[{"permissions":`+tt.Input+`}]}`), &conf); err != nil {
if tt.Error == "" {
t.Errorf("unexpected error: %s", err)
}
if tt.Error != err.Error() {
t.Errorf("expected error: %s, got: %s", tt.Error, err)
}
return
}
permissions := conf.Apps[0].Permissions
if permissions.Read != tt.Output.Read {
t.Errorf("expected Read: %t, got: %t", tt.Output.Read, permissions.Read)
}
if permissions.Write != tt.Output.Write {
t.Errorf("expected Write: %t, got: %t", tt.Output.Write, permissions.Write)
}
if permissions.Delete != tt.Output.Delete {
t.Errorf("expected Delete: %t, got: %t", tt.Output.Delete, permissions.Delete)
}
})
}
}