Skip to content

Commit

Permalink
common tests framework: cluster client creation fail with invalid auth
Browse files Browse the repository at this point in the history
Signed-off-by: Chao Chen <[email protected]>
  • Loading branch information
chaochn47 committed Aug 10, 2022
1 parent 78a4b64 commit e2dffb0
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 74 deletions.
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
11 changes: 6 additions & 5 deletions tests/common/compact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,28 @@ func TestCompact(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 3})
defer clus.Close()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}
for i := range kvs {
if err := clus.Client().Put(kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil {
if err := cc.Put(kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil {
t.Fatalf("compactTest #%d: put kv error (%v)", i, err)
}
}
get, err := clus.Client().Get("key", config.GetOptions{Revision: 3})
get, err := cc.Get("key", config.GetOptions{Revision: 3})
if err != nil {
t.Fatalf("compactTest: Get kv by revision error (%v)", err)
}

getkvs := testutils.KeyValuesFromGetResponse(get)
assert.Equal(t, kvs[1:2], getkvs)

_, err = clus.Client().Compact(4, tc.options)
_, err = cc.Compact(4, tc.options)
if err != nil {
t.Fatalf("compactTest: Compact error (%v)", err)
}

get, err = clus.Client().Get("key", config.GetOptions{Revision: 3})
get, err = cc.Get("key", config.GetOptions{Revision: 3})
if err != nil {
if !strings.Contains(err.Error(), "required revision has been compacted") {
t.Fatalf("compactTest: Get compact key error (%v)", err)
Expand All @@ -76,7 +77,7 @@ func TestCompact(t *testing.T) {
t.Fatalf("expected '...has been compacted' error, got <nil>")
}

_, err = clus.Client().Compact(2, tc.options)
_, err = cc.Compact(2, tc.options)
if err != nil {
if !strings.Contains(err.Error(), "required revision has been compacted") {
t.Fatal(err)
Expand Down
7 changes: 4 additions & 3 deletions tests/common/defrag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ func TestDefragOnline(t *testing.T) {
defer cancel()
options := config.DefragOption{Timeout: 10 * time.Second}
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 3})
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
defer clus.Close()
var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}
for i := range kvs {
if err := clus.Client().Put(kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil {
if err := cc.Put(kvs[i].Key, kvs[i].Val, config.PutOptions{}); err != nil {
t.Fatalf("compactTest #%d: put kv error (%v)", i, err)
}
}
_, err := clus.Client().Compact(4, config.CompactOption{Physical: true, Timeout: 10 * time.Second})
_, err := cc.Compact(4, config.CompactOption{Physical: true, Timeout: 10 * time.Second})
if err != nil {
t.Fatalf("defrag_test: compact with revision error (%v)", err)
}

if err = clus.Client().Defragment(options); err != nil {
if err = cc.Defragment(options); err != nil {
t.Fatalf("defrag_test: defrag error (%v)", err)
}
})
Expand Down
9 changes: 6 additions & 3 deletions tests/common/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func TestEndpointStatus(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 3})
defer clus.Close()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
_, err := clus.Client().Status()
_, err := cc.Status()
if err != nil {
t.Fatalf("get endpoint status error: %v", err)
}
Expand All @@ -43,8 +44,9 @@ func TestEndpointHashKV(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 3})
defer clus.Close()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
_, err := clus.Client().HashKV(0)
_, err := cc.HashKV(0)
if err != nil {
t.Fatalf("get endpoint hashkv error: %v", err)
}
Expand All @@ -57,8 +59,9 @@ func TestEndpointHealth(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 3})
defer clus.Close()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
if err := clus.Client().Health(); err != nil {
if err := cc.Health(); err != nil {
t.Fatalf("get endpoint health error: %v", err)
}
})
Expand Down
6 changes: 3 additions & 3 deletions tests/common/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestKVPut(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
key, value := "foo", "bar"
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestKVGet(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
var (
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestKVDelete(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
kvs := []string{"a", "b", "c", "c/abc", "d"}
tests := []struct {
Expand Down
10 changes: 5 additions & 5 deletions tests/common/lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestLeaseGrantTimeToLive(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
ttl := int64(10)
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestLeaseGrantAndList(t *testing.T) {
t.Logf("Creating cluster...")
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})
t.Logf("Created cluster and client")
testutils.ExecuteUntil(ctx, t, func() {
createdLeases := []clientv3.LeaseID{}
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestLeaseGrantTimeToLiveExpired(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
leaseResp, err := cc.Grant(2)
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
leaseResp, err := cc.Grant(2)
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestLeaseGrantRevoke(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
leaseResp, err := cc.Grant(20)
Expand Down
6 changes: 4 additions & 2 deletions tests/common/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package common

import (
"context"
"go.etcd.io/etcd/tests/v3/framework/testutils"
"testing"
"time"

"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)

func TestMemberList(t *testing.T) {
Expand All @@ -30,7 +32,7 @@ func TestMemberList(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
resp, err := cc.MemberList()
Expand Down
10 changes: 5 additions & 5 deletions tests/common/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRoleAdd_Simple(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd("root")
Expand All @@ -52,7 +52,7 @@ func TestRoleAdd_Error(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 1})
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd("test-role")
if err != nil {
Expand All @@ -75,7 +75,7 @@ func TestRootRole(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 1})
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd("root")
if err != nil {
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestRoleGrantRevokePermission(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 1})
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd("role1")
if err != nil {
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestRoleDelete(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.ClusterConfig{ClusterSize: 1})
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd("role1")
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion tests/common/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"
"time"

"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)

Expand All @@ -32,7 +33,7 @@ func TestStatus(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
rs, err := cc.Status()
Expand Down
4 changes: 2 additions & 2 deletions tests/common/txn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestTxnSucc(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, cfg.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
if err := cc.Put("key1", "value1", config.PutOptions{}); err != nil {
t.Fatalf("could not create key:%s, value:%s", "key1", "value1")
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestTxnFail(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, cfg.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})
testutils.ExecuteUntil(ctx, t, func() {
if err := cc.Put("key1", "value1", config.PutOptions{}); err != nil {
t.Fatalf("could not create key:%s, value:%s", "key1", "value1")
Expand Down
10 changes: 5 additions & 5 deletions tests/common/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestUserAdd_Simple(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
resp, err := cc.UserAdd(nc.username, nc.password, config.UserAddOptions{NoPassword: nc.noPassword})
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestUserAdd_DuplicateUserNotAllowed(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
user := "barb"
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestUserList(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
// No Users Yet
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestUserDelete(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
user := "barb"
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestUserChangePassword(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, tc.config)
defer clus.Close()
cc := clus.Client()
cc := clus.MustClient(config.ClientOption{})

testutils.ExecuteUntil(ctx, t, func() {
user := "barb"
Expand Down
Loading

0 comments on commit e2dffb0

Please sign in to comment.