Skip to content

Commit

Permalink
migrate auth tests to common
Browse files Browse the repository at this point in the history
Signed-off-by: Chao Chen <[email protected]>
  • Loading branch information
chaochn47 committed Aug 4, 2022
1 parent ae36a57 commit 394540f
Show file tree
Hide file tree
Showing 20 changed files with 1,377 additions and 889 deletions.
2 changes: 2 additions & 0 deletions server/auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ func (as *authStore) RoleGrantPermission(r *pb.AuthRoleGrantPermissionRequest) (
"granted/updated a permission to a user",
zap.String("user-name", r.Name),
zap.String("permission-name", authpb.Permission_Type_name[int32(r.Perm.PermType)]),
zap.ByteString("key", r.Perm.Key),
zap.ByteString("range-end", r.Perm.RangeEnd),
)
return &pb.AuthRoleGrantPermissionResponse{}, nil
}
Expand Down
19 changes: 10 additions & 9 deletions tests/common/alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ func TestAlarm(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 1, QuotaBackendBytes: int64(13 * os.Getpagesize())})
defer clus.Close()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
// test small put still works
smallbuf := strings.Repeat("a", 64)
if err := clus.Client().Put("1st_test", smallbuf, config.PutOptions{}); err != nil {
if err := cc.Put("1st_test", smallbuf, config.PutOptions{}); err != nil {
t.Fatalf("alarmTest: put kv error (%v)", err)
}

// write some chunks to fill up the database
buf := strings.Repeat("b", os.Getpagesize())
for {
if err := clus.Client().Put("2nd_test", buf, config.PutOptions{}); err != nil {
if err := cc.Put("2nd_test", buf, config.PutOptions{}); err != nil {
if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
t.Fatal(err)
}
Expand All @@ -51,20 +52,20 @@ func TestAlarm(t *testing.T) {
}

// quota alarm should now be on
alarmResp, err := clus.Client().AlarmList()
alarmResp, err := cc.AlarmList()
if err != nil {
t.Fatalf("alarmTest: Alarm error (%v)", err)
}

// check that Put is rejected when alarm is on
if err := clus.Client().Put("3rd_test", smallbuf, config.PutOptions{}); err != nil {
if err := cc.Put("3rd_test", smallbuf, config.PutOptions{}); err != nil {
if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
t.Fatal(err)
}
}

// get latest revision to compact
sresp, err := clus.Client().Status()
sresp, err := cc.Status()
if err != nil {
t.Fatalf("get endpoint status error: %v", err)
}
Expand All @@ -77,12 +78,12 @@ func TestAlarm(t *testing.T) {
}

// make some space
_, err = clus.Client().Compact(rvs, config.CompactOption{Physical: true, Timeout: 10 * time.Second})
_, err = cc.Compact(rvs, config.CompactOption{Physical: true, Timeout: 10 * time.Second})
if err != nil {
t.Fatalf("alarmTest: Compact error (%v)", err)
}

if err = clus.Client().Defragment(config.DefragOption{Timeout: 10 * time.Second}); err != nil {
if err = cc.Defragment(config.DefragOption{Timeout: 10 * time.Second}); err != nil {
t.Fatalf("alarmTest: defrag error (%v)", err)
}

Expand All @@ -92,14 +93,14 @@ func TestAlarm(t *testing.T) {
MemberID: alarm.MemberID,
Alarm: alarm.Alarm,
}
_, err = clus.Client().AlarmDisarm(alarmMember)
_, err = cc.AlarmDisarm(alarmMember)
if err != nil {
t.Fatalf("alarmTest: Alarm error (%v)", err)
}
}

// put one more key below quota
if err := clus.Client().Put("4th_test", smallbuf, config.PutOptions{}); err != nil {
if err := cc.Put("4th_test", smallbuf, config.PutOptions{}); err != nil {
t.Fatal(err)
}
})
Expand Down
Loading

0 comments on commit 394540f

Please sign in to comment.