From 3ee2f5711e1c5b4030a84a06f907295ffa92fb7b Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Tue, 25 Oct 2022 02:41:43 +0800 Subject: [PATCH] test: add common function "WithAuth" We defines two common `WithAuth` functions for e2e and integration test respectively. They are calling `integration.WithAuth` and `e2e.WithAuth` respectively. Signed-off-by: Benjamin Wang --- tests/common/e2e_test.go | 10 +++++++++- tests/common/integration_test.go | 6 ++++++ tests/framework/config/client.go | 7 ++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/common/e2e_test.go b/tests/common/e2e_test.go index 1debbafaa..1284714b1 100644 --- a/tests/common/e2e_test.go +++ b/tests/common/e2e_test.go @@ -17,8 +17,16 @@ package common -import "go.etcd.io/etcd/tests/v3/framework" +import ( + "go.etcd.io/etcd/tests/v3/framework" + "go.etcd.io/etcd/tests/v3/framework/config" + "go.etcd.io/etcd/tests/v3/framework/e2e" +) func init() { testRunner = framework.E2eTestRunner } + +func WithAuth(userName, password string) config.ClientOption { + return e2e.WithAuth(userName, password) +} diff --git a/tests/common/integration_test.go b/tests/common/integration_test.go index a2588a9cc..d875dbc82 100644 --- a/tests/common/integration_test.go +++ b/tests/common/integration_test.go @@ -19,8 +19,14 @@ package common import ( "go.etcd.io/etcd/tests/v3/framework" + "go.etcd.io/etcd/tests/v3/framework/config" + "go.etcd.io/etcd/tests/v3/framework/integration" ) func init() { testRunner = framework.IntegrationTestRunner } + +func WithAuth(userName, password string) config.ClientOption { + return integration.WithAuth(userName, password) +} diff --git a/tests/framework/config/client.go b/tests/framework/config/client.go index 124d2eb3d..e570c9c11 100644 --- a/tests/framework/config/client.go +++ b/tests/framework/config/client.go @@ -21,9 +21,10 @@ import ( ) // ClientOption configures the client with additional parameter. -// For example, if Auth is enabled, -// 1. e2e test cases use e2e.WithAuth to return a ClientOption; -// 2. integration test, uses integration.WithAuth to return a ClientOption. +// For example, if Auth is enabled, the common test cases just need to +// use `WithAuth` to return a ClientOption. Note that the common `WithAuth` +// function calls `e2e.WithAuth` or `integration.WithAuth`, depending on the +// build tag (either "e2e" or "integration"). type ClientOption func(any) type GetOptions struct {