Skip to content

Commit

Permalink
rebase, new Client interface
Browse files Browse the repository at this point in the history
  • Loading branch information
veshij committed Oct 26, 2022
1 parent 402619d commit d30068b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
7 changes: 3 additions & 4 deletions tests/e2e/ctl_v3_auth_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func TestAuthCluster(t *testing.T) {
cfg := e2e.NewConfigNoTLS()
cfg.ClusterSize = 1
cfg.SnapshotCount = 2
cfg.UserName = rootUser
cfg.Password = rootPassword
cfg.ClientAuthOpts = []config.ClientOption{e2e.WithAuth(rootUser, rootPassword)}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -50,13 +49,13 @@ func TestAuthCluster(t *testing.T) {
t.Fatalf("could not enable Auth: (%v)", err)
}

writeKeys(ctx, epc.Client().WithAuth(testUser, testPassword), "test")
writeKeys(ctx, epc.Client(e2e.WithAuth(testUser, testPassword)), "test")

if err := epc.StartNewProc(ctx, t); err != nil {
t.Fatalf("could not start second etcd process (%v)", err)
}

writeKeys(ctx, epc.Client().WithAuth(testUser, testPassword), "test_two_nodes")
writeKeys(ctx, epc.Client(e2e.WithAuth(testUser, testPassword)), "test_two_nodes")

hashKvs, err := epc.Client().HashKV(ctx, numKeys*2)
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package e2e
import (
"context"
"fmt"
"go.etcd.io/etcd/tests/v3/framework/config"
"net/url"
"path"
"regexp"
Expand Down Expand Up @@ -184,8 +185,7 @@ type EtcdProcessClusterConfig struct {
CompactHashCheckTime time.Duration
GoFailEnabled bool

UserName string // user/password pair to be used for client connections
Password string
ClientAuthOpts []config.ClientOption
}

// NewEtcdProcessCluster launches a new cluster from etcd processes, returning
Expand Down Expand Up @@ -615,12 +615,11 @@ func (epc *EtcdProcessCluster) Stop() (err error) {
return err
}

func (epc *EtcdProcessCluster) Client() *EtcdctlV3 {
client := NewEtcdctl(epc.Cfg, epc.EndpointsV3())
if epc.Cfg.UserName != "" {
client = client.WithAuth(epc.Cfg.UserName, epc.Cfg.Password)
func (epc *EtcdProcessCluster) Client(opts ...config.ClientOption) *EtcdctlV3 {
if len(epc.Cfg.ClientAuthOpts) > 0 {
opts = append(opts, epc.Cfg.ClientAuthOpts...)
}
return client
return NewEtcdctl(epc.Cfg, epc.EndpointsV3(), opts...)
}

func (epc *EtcdProcessCluster) Close() error {
Expand Down

0 comments on commit d30068b

Please sign in to comment.