Merge pull request #14683 from ahrtr/test_framework_20221104

test: refactor the framework structure to make it clearer
dependabot/go_modules/go.uber.org/atomic-1.10.0
Benjamin Wang 2022-11-05 04:30:59 +08:00 committed by GitHub
commit d71762f4f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 107 additions and 109 deletions

View File

@ -22,7 +22,6 @@ import (
"time"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -36,7 +35,7 @@ func TestAlarm(t *testing.T) {
config.WithQuotaBackendBytes(int64(13*os.Getpagesize())),
)
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
// test small put still works
smallbuf := strings.Repeat("a", 64)
@ -120,7 +119,7 @@ func TestAlarmlistOnMemberRestart(t *testing.T) {
config.WithSnapshotCount(5),
)
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
for i := 0; i < 6; i++ {

View File

@ -21,7 +21,6 @@ import (
"time"
"github.com/stretchr/testify/assert"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -48,7 +47,7 @@ func TestCompact(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
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 {

View File

@ -19,7 +19,6 @@ import (
"testing"
"time"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -30,7 +29,7 @@ func TestDefragOnline(t *testing.T) {
defer cancel()
options := config.DefragOption{Timeout: 10 * time.Second}
clus := testRunner.NewCluster(ctx, t)
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
defer clus.Close()
var kvs = []testutils.KV{{Key: "key", Val: "val1"}, {Key: "key", Val: "val2"}, {Key: "key", Val: "val3"}}

View File

@ -19,7 +19,6 @@ import (
"testing"
"time"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -29,7 +28,7 @@ func TestEndpointStatus(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.Status(ctx)
if err != nil {
@ -44,7 +43,7 @@ func TestEndpointHashKV(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.HashKV(ctx, 0)
if err != nil {
@ -59,7 +58,7 @@ func TestEndpointHealth(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t)
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
if err := cc.Health(ctx); err != nil {
t.Fatalf("get endpoint health error: %v", err)

View File

@ -21,7 +21,6 @@ import (
"github.com/stretchr/testify/assert"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -34,7 +33,7 @@ func TestKVPut(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
key, value := "foo", "bar"
@ -68,7 +67,7 @@ func TestKVGet(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
var (
@ -128,7 +127,7 @@ func TestKVDelete(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
kvs := []string{"a", "b", "c", "c/abc", "d"}
tests := []struct {

View File

@ -21,7 +21,6 @@ import (
"github.com/stretchr/testify/require"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -35,7 +34,7 @@ func TestLeaseGrantTimeToLive(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
ttl := int64(10)
@ -79,7 +78,7 @@ func TestLeaseGrantAndList(t *testing.T) {
t.Logf("Creating cluster...")
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
t.Logf("Created cluster and client")
testutils.ExecuteUntil(ctx, t, func() {
var createdLeases []clientv3.LeaseID
@ -126,7 +125,7 @@ func TestLeaseGrantTimeToLiveExpired(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
leaseResp, err := cc.Grant(ctx, 2)
@ -163,7 +162,7 @@ func TestLeaseGrantKeepAliveOnce(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
leaseResp, err := cc.Grant(ctx, 2)
@ -192,7 +191,7 @@ func TestLeaseGrantRevoke(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
leaseResp, err := cc.Grant(ctx, 20)

View File

@ -17,11 +17,11 @@ package common
import (
"testing"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
intf "go.etcd.io/etcd/tests/v3/framework/interfaces"
)
var testRunner framework.TestRunner
var testRunner intf.TestRunner
var clusterTestCases = []testCase{
{

View File

@ -22,8 +22,8 @@ import (
"github.com/stretchr/testify/require"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/etcdserver"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
intf "go.etcd.io/etcd/tests/v3/framework/interfaces"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -36,7 +36,7 @@ func TestMemberList(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
resp, err := cc.MemberList(ctx)
@ -110,7 +110,7 @@ func TestMemberAdd(t *testing.T) {
c.StrictReconfigCheck = quorumTc.strictReconfigCheck
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(c))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
var addResp *clientv3.MemberAddResponse
@ -235,7 +235,7 @@ func TestMemberRemove(t *testing.T) {
// If clusterSize == 1, return the only member.
// Otherwise, return a member that client has not connected to.
// It ensures that `MemberRemove` function does not return an "etcdserver: server stopped" error.
func memberToRemove(ctx context.Context, t *testing.T, client framework.Client, clusterSize int) (memberId uint64, clusterId uint64) {
func memberToRemove(ctx context.Context, t *testing.T, client intf.Client, clusterSize int) (memberId uint64, clusterId uint64) {
listResp, err := client.MemberList(ctx)
if err != nil {
t.Fatal(err)

View File

@ -22,7 +22,6 @@ import (
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -35,7 +34,7 @@ func TestRoleAdd_Simple(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd(ctx, "root")
@ -53,7 +52,7 @@ func TestRoleAdd_Error(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterSize(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd(ctx, "test-role")
if err != nil {
@ -76,7 +75,7 @@ func TestRootRole(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterSize(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd(ctx, "root")
if err != nil {
@ -106,7 +105,7 @@ func TestRoleGrantRevokePermission(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterSize(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd(ctx, "role1")
if err != nil {
@ -141,7 +140,7 @@ func TestRoleDelete(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterSize(1))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
_, err := cc.RoleAdd(ctx, "role1")
if err != nil {

View File

@ -19,7 +19,6 @@ import (
"testing"
"time"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -34,7 +33,7 @@ func TestStatus(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
rs, err := cc.Status(ctx)

View File

@ -23,7 +23,6 @@ import (
"github.com/stretchr/testify/assert"
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -61,7 +60,7 @@ func TestTxnSucc(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(cfg.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
if err := cc.Put(ctx, "key1", "value1", config.PutOptions{}); err != nil {
t.Fatalf("could not create key:%s, value:%s", "key1", "value1")
@ -105,7 +104,7 @@ func TestTxnFail(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(cfg.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
if err := cc.Put(ctx, "key1", "value1", config.PutOptions{}); err != nil {
t.Fatalf("could not create key:%s, value:%s", "key1", "value1")

View File

@ -20,7 +20,6 @@ import (
"time"
"github.com/stretchr/testify/assert"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -69,7 +68,7 @@ func TestUserAdd_Simple(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
resp, err := cc.UserAdd(ctx, nc.username, nc.password, config.UserAddOptions{NoPassword: nc.noPassword})
@ -103,7 +102,7 @@ func TestUserAdd_DuplicateUserNotAllowed(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
user := "barb"
@ -132,7 +131,7 @@ func TestUserList(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
// No Users Yet
@ -173,7 +172,7 @@ func TestUserDelete(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
user := "barb"
@ -225,7 +224,7 @@ func TestUserChangePassword(t *testing.T) {
defer cancel()
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
user := "barb"

View File

@ -6,7 +6,6 @@ import (
"time"
"github.com/stretchr/testify/assert"
"go.etcd.io/etcd/tests/v3/framework"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
@ -21,7 +20,7 @@ func TestWatch(t *testing.T) {
clus := testRunner.NewCluster(ctx, t, config.WithClusterConfig(tc.config))
defer clus.Close()
cc := framework.MustClient(clus.Client())
cc := testutils.MustClient(clus.Client())
testutils.ExecuteUntil(ctx, t, func() {
tests := []struct {
puts []testutils.KV

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package framework
package e2e
import (
"context"
@ -23,13 +23,18 @@ import (
"go.etcd.io/etcd/client/pkg/v3/testutil"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/e2e"
intf "go.etcd.io/etcd/tests/v3/framework/interfaces"
"go.etcd.io/etcd/tests/v3/framework/testutils"
)
type e2eRunner struct{}
func NewE2eRunner() intf.TestRunner {
return &e2eRunner{}
}
func (e e2eRunner) TestMain(m *testing.M) {
e2e.InitFlags()
InitFlags()
v := m.Run()
if v == 0 && testutil.CheckLeakedGoroutine() {
os.Exit(1)
@ -38,12 +43,12 @@ func (e e2eRunner) TestMain(m *testing.M) {
}
func (e e2eRunner) BeforeTest(t testing.TB) {
e2e.BeforeTest(t)
BeforeTest(t)
}
func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) Cluster {
func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) intf.Cluster {
cfg := config.NewClusterConfig(opts...)
e2eConfig := e2e.EtcdProcessClusterConfig{
e2eConfig := EtcdProcessClusterConfig{
InitialToken: "new",
ClusterSize: cfg.ClusterSize,
QuotaBackendBytes: cfg.QuotaBackendBytes,
@ -53,13 +58,13 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.
}
switch cfg.ClientTLS {
case config.NoTLS:
e2eConfig.ClientTLS = e2e.ClientNonTLS
e2eConfig.ClientTLS = ClientNonTLS
case config.AutoTLS:
e2eConfig.IsClientAutoTLS = true
e2eConfig.ClientTLS = e2e.ClientTLS
e2eConfig.ClientTLS = ClientTLS
case config.ManualTLS:
e2eConfig.IsClientAutoTLS = false
e2eConfig.ClientTLS = e2e.ClientTLS
e2eConfig.ClientTLS = ClientTLS
default:
t.Fatalf("ClientTLS config %q not supported", cfg.ClientTLS)
}
@ -76,7 +81,7 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.
default:
t.Fatalf("PeerTLS config %q not supported", cfg.PeerTLS)
}
epc, err := e2e.NewEtcdProcessCluster(ctx, t, &e2eConfig)
epc, err := NewEtcdProcessCluster(ctx, t, &e2eConfig)
if err != nil {
t.Fatalf("could not start etcd integrationCluster: %s", err)
}
@ -85,11 +90,11 @@ func (e e2eRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.
type e2eCluster struct {
t testing.TB
e2e.EtcdProcessCluster
EtcdProcessCluster
}
func (c *e2eCluster) Client(opts ...config.ClientOption) (Client, error) {
etcdctl, err := e2e.NewEtcdctl(c.Cfg, c.EndpointsV3(), opts...)
func (c *e2eCluster) Client(opts ...config.ClientOption) (intf.Client, error) {
etcdctl, err := NewEtcdctl(c.Cfg, c.EndpointsV3(), opts...)
return e2eClient{etcdctl}, err
}
@ -97,7 +102,7 @@ func (c *e2eCluster) Endpoints() []string {
return c.EndpointsV3()
}
func (c *e2eCluster) Members() (ms []Member) {
func (c *e2eCluster) Members() (ms []intf.Member) {
for _, proc := range c.EtcdProcessCluster.Procs {
ms = append(ms, e2eMember{EtcdProcess: proc, Cfg: c.Cfg})
}
@ -114,8 +119,8 @@ func (c *e2eCluster) WaitLeader(t testing.TB) int {
// WaitMembersForLeader waits until given members agree on the same leader,
// and returns its 'index' in the 'membs' list
func (c *e2eCluster) WaitMembersForLeader(ctx context.Context, t testing.TB, membs []Member) int {
cc := MustClient(c.Client())
func (c *e2eCluster) WaitMembersForLeader(ctx context.Context, t testing.TB, membs []intf.Member) int {
cc := testutils.MustClient(c.Client())
// ensure leader is up via linearizable get
for {
@ -171,16 +176,16 @@ func (c *e2eCluster) WaitMembersForLeader(ctx context.Context, t testing.TB, mem
}
type e2eClient struct {
*e2e.EtcdctlV3
*EtcdctlV3
}
type e2eMember struct {
e2e.EtcdProcess
Cfg *e2e.EtcdProcessClusterConfig
EtcdProcess
Cfg *EtcdProcessClusterConfig
}
func (m e2eMember) Client() Client {
etcdctl, err := e2e.NewEtcdctl(m.Cfg, m.EndpointsV3())
func (m e2eMember) Client() intf.Client {
etcdctl, err := NewEtcdctl(m.Cfg, m.EndpointsV3())
if err != nil {
panic(err)
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package framework
package integration
import (
"context"
@ -22,30 +22,35 @@ import (
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"go.uber.org/zap"
"go.etcd.io/etcd/client/pkg/v3/testutil"
"go.etcd.io/etcd/client/pkg/v3/transport"
clientv3 "go.etcd.io/etcd/client/v3"
etcdctlcmd "go.etcd.io/etcd/etcdctl/v3/ctlv3/command"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/integration"
"go.uber.org/zap"
intf "go.etcd.io/etcd/tests/v3/framework/interfaces"
)
type integrationRunner struct{}
func NewIntegrationRunner() intf.TestRunner {
return &integrationRunner{}
}
func (e integrationRunner) TestMain(m *testing.M) {
testutil.MustTestMainWithLeakDetection(m)
}
func (e integrationRunner) BeforeTest(t testing.TB) {
integration.BeforeTest(t)
BeforeTest(t)
}
func (e integrationRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) Cluster {
func (e integrationRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) intf.Cluster {
var err error
cfg := config.NewClusterConfig(opts...)
integrationCfg := integration.ClusterConfig{
integrationCfg := ClusterConfig{
Size: cfg.ClusterSize,
QuotaBackendBytes: cfg.QuotaBackendBytes,
DisableStrictReconfigCheck: !cfg.StrictReconfigCheck,
@ -61,7 +66,7 @@ func (e integrationRunner) NewCluster(ctx context.Context, t testing.TB, opts ..
t.Fatalf("PeerTLS: %s", err)
}
return &integrationCluster{
Cluster: integration.NewCluster(t, &integrationCfg),
Cluster: NewCluster(t, &integrationCfg),
t: t,
ctx: ctx,
}
@ -78,19 +83,19 @@ func tlsInfo(t testing.TB, cfg config.TLSConfig) (*transport.TLSInfo, error) {
}
return &tls, nil
case config.ManualTLS:
return &integration.TestTLSInfo, nil
return &TestTLSInfo, nil
default:
return nil, fmt.Errorf("config %q not supported", cfg)
}
}
type integrationCluster struct {
*integration.Cluster
*Cluster
t testing.TB
ctx context.Context
}
func (c *integrationCluster) Members() (ms []Member) {
func (c *integrationCluster) Members() (ms []intf.Member) {
for _, m := range c.Cluster.Members {
ms = append(ms, integrationMember{Member: m, t: c.t})
}
@ -98,11 +103,11 @@ func (c *integrationCluster) Members() (ms []Member) {
}
type integrationMember struct {
*integration.Member
*Member
t testing.TB
}
func (m integrationMember) Client() Client {
func (m integrationMember) Client() intf.Client {
return integrationClient{Client: m.Member.Client}
}
@ -119,7 +124,7 @@ func (c *integrationCluster) Close() error {
return nil
}
func (c *integrationCluster) Client(opts ...config.ClientOption) (Client, error) {
func (c *integrationCluster) Client(opts ...config.ClientOption) (intf.Client, error) {
cc, err := c.ClusterClient(c.t, opts...)
if err != nil {
return nil, err

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package framework
package interfaces
import (
"context"

View File

@ -14,11 +14,19 @@
package framework
import (
intf "go.etcd.io/etcd/tests/v3/framework/interfaces"
"go.etcd.io/etcd/tests/v3/framework/e2e"
"go.etcd.io/etcd/tests/v3/framework/integration"
"go.etcd.io/etcd/tests/v3/framework/unit"
)
var (
// UnitTestRunner only runs in `--short` mode, will fail otherwise. Attempts in cluster creation will result in tests being skipped.
UnitTestRunner TestRunner = unitRunner{}
UnitTestRunner intf.TestRunner = unit.NewUnitRunner()
// E2eTestRunner runs etcd and etcdctl binaries in a separate process.
E2eTestRunner = e2eRunner{}
E2eTestRunner = e2e.NewE2eRunner()
// IntegrationTestRunner runs etcdserver.EtcdServer in separate goroutine and uses client libraries to communicate.
IntegrationTestRunner = integrationRunner{}
IntegrationTestRunner = integration.NewIntegrationRunner()
)

View File

@ -19,6 +19,7 @@ import (
"time"
clientv3 "go.etcd.io/etcd/client/v3"
intf "go.etcd.io/etcd/tests/v3/framework/interfaces"
)
type KV struct {
@ -61,3 +62,10 @@ func KeyValuesFromWatchChan(wch clientv3.WatchChan, wantedLen int, timeout time.
}
}
}
func MustClient(c intf.Client, err error) intf.Client {
if err != nil {
panic(err)
}
return c
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package framework
package unit
import (
"context"
@ -23,11 +23,16 @@ import (
"go.etcd.io/etcd/client/pkg/v3/testutil"
"go.etcd.io/etcd/tests/v3/framework/config"
intf "go.etcd.io/etcd/tests/v3/framework/interfaces"
)
type unitRunner struct{}
var _ TestRunner = (*unitRunner)(nil)
var _ intf.TestRunner = (*unitRunner)(nil)
func NewUnitRunner() intf.TestRunner {
return &unitRunner{}
}
func (e unitRunner) TestMain(m *testing.M) {
flag.Parse()
@ -40,7 +45,7 @@ func (e unitRunner) TestMain(m *testing.M) {
func (e unitRunner) BeforeTest(t testing.TB) {
}
func (e unitRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) Cluster {
func (e unitRunner) NewCluster(ctx context.Context, t testing.TB, opts ...config.ClusterOption) intf.Cluster {
testutil.SkipTestIfShortMode(t, "Cannot create clusters in --short tests")
return nil
}

View File

@ -1,22 +0,0 @@
// Copyright 2022 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package framework
func MustClient(c Client, err error) Client {
if err != nil {
panic(err)
}
return c
}