...
1
2
3
4
5
6
7
8
9
10
11
12
13 package driver
14
15 import (
16 "encoding/json"
17 "testing"
18 )
19
20 func TestSecurityMarshalJSON(t *testing.T) {
21 t.Run("empty", func(t *testing.T) {
22 sec := Security{}
23 want := "{}"
24 got, _ := json.Marshal(sec)
25 if string(got) != want {
26 t.Errorf("Unexpected output: %s", string(got))
27 }
28 })
29 t.Run("pointer", func(t *testing.T) {
30 sec := &Security{}
31 want := "{}"
32 got, _ := json.Marshal(sec)
33 if string(got) != want {
34 t.Errorf("Unexpected output: %s", string(got))
35 }
36 })
37 t.Run("admin name, one member role", func(t *testing.T) {
38 sec := Security{
39 Admins: Members{
40 Names: []string{"bob"},
41 },
42 Members: Members{
43 Roles: []string{"users"},
44 },
45 }
46 want := `{"admins":{"names":["bob"]},"members":{"roles":["users"]}}`
47 got, _ := json.Marshal(sec)
48 if string(got) != want {
49 t.Errorf("Unexpected output: %s", string(got))
50 }
51 })
52 }
53
View as plain text