Skip to content

Commit

Permalink
add ut for enhancement.
Browse files Browse the repository at this point in the history
format tune.

revert betesting

define []byte("*") as allKeys, reuse it.
  • Loading branch information
horizonzy committed May 17, 2021
1 parent 77a73d4 commit 1ce84ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ var (
authEnabled = []byte{1}
authDisabled = []byte{0}

rootPerm = authpb.Permission{PermType: authpb.READWRITE, Key: []byte("*")}
allKeys = []byte("*")
rootPerm = authpb.Permission{PermType: authpb.READWRITE, Key: allKeys, RangeEnd: []byte{0}}

revisionKey = []byte("authRevision")

Expand Down
22 changes: 22 additions & 0 deletions server/auth/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,28 @@ func TestUserGrant(t *testing.T) {
}
}

func TestGetRootRole(t *testing.T) {
as, tearDown := setupAuthStore(t)
defer tearDown(t)

perm := &authpb.Permission{
PermType: authpb.READWRITE,
Key: allKeys,
RangeEnd: []byte{0},
}

//get root role
r, err := as.RoleGet(&pb.AuthRoleGetRequest{Role: "root"})
if err != nil {
t.Fatal(err)
}

//check the role is root
if !reflect.DeepEqual(perm, r.Perm[0]) {
t.Errorf("expected %v, got %v", perm, r.Perm[0])
}
}

func TestHasRole(t *testing.T) {
as, tearDown := setupAuthStore(t)
defer tearDown(t)
Expand Down

0 comments on commit 1ce84ec

Please sign in to comment.