|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "testing" |
5 | 6 |
|
6 | 7 | "github.com/jech/galene/group" |
@@ -38,3 +39,29 @@ func TestMakePassword(t *testing.T) { |
38 | 39 | t.Errorf("Wildcard didn't match") |
39 | 40 | } |
40 | 41 | } |
| 42 | + |
| 43 | +func TestFormatPermissions(t *testing.T) { |
| 44 | + tests := []struct{ j, v, p string }{ |
| 45 | + {`"op"`, "op", "[mopt]"}, |
| 46 | + {`"present"`, "present", "[mp]"}, |
| 47 | + {`"observe"`, "observe", "[]"}, |
| 48 | + {`"admin"`, "admin", "[a]"}, |
| 49 | + {`["message", "present", "token"]`, "[mpt]", "[mpt]"}, |
| 50 | + } |
| 51 | + for _, test := range tests { |
| 52 | + var p group.Permissions |
| 53 | + err := json.Unmarshal([]byte(test.j), &p) |
| 54 | + if err != nil { |
| 55 | + t.Errorf("Unmarshal %#v: %v", test.j, err) |
| 56 | + continue |
| 57 | + } |
| 58 | + v := formatPermissions(p) |
| 59 | + if v != test.v { |
| 60 | + t.Errorf("Expected %v, got %v", test.v, v) |
| 61 | + } |
| 62 | + pp := formatRawPermissions(p.Permissions(nil)) |
| 63 | + if pp != test.p { |
| 64 | + t.Errorf("Expected %v, got %v", test.p, pp) |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments