(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func TestUserPermissionFromRole(t *testing.T) { |
| 27 | Convey("test marshal/unmarshal json", t, func() { |
| 28 | jsonBytes, err := json.Marshal(Read) |
| 29 | So(err, ShouldBeNil) |
| 30 | So(jsonBytes, ShouldResemble, []byte(`"Read"`)) |
| 31 | var r UserPermissionRole |
| 32 | So(r, ShouldEqual, Void) |
| 33 | err = json.Unmarshal([]byte(`"Write"`), &r) |
| 34 | So(err, ShouldBeNil) |
| 35 | So(r, ShouldEqual, Write) |
| 36 | err = r.UnmarshalJSON([]byte(`"Read,Write"`)) |
| 37 | So(err, ShouldBeNil) |
| 38 | So(r, ShouldEqual, ReadWrite) |
| 39 | }) |
| 40 | Convey("test string/from string", t, func() { |
| 41 | var r UserPermissionRole |
| 42 | So(r, ShouldEqual, Void) |
| 43 | r.FromString(Read.String()) |
| 44 | So(r, ShouldEqual, Read) |
| 45 | r.FromString(Void.String()) |
| 46 | So(r, ShouldEqual, Void) |
| 47 | r.FromString(ReadWrite.String()) |
| 48 | So(r, ShouldEqual, ReadWrite) |
| 49 | r.FromString(Admin.String()) |
| 50 | So(r, ShouldEqual, Admin) |
| 51 | |
| 52 | // tricky case |
| 53 | trickyStr := "Write,Super" |
| 54 | r.FromString(trickyStr) |
| 55 | So(r, ShouldEqual, Write|Super) |
| 56 | So(r.String(), ShouldEqual, trickyStr) |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | func TestUserPermission(t *testing.T) { |
| 61 | Convey("nil protect", t, func() { |
nothing calls this directly
no test coverage detected