tests: Rename framework to runner and document the runners

This commit is contained in:
Marek Siarkowicz
2022-02-23 16:41:21 +01:00
parent def122871c
commit 65be41dd6e
9 changed files with 27 additions and 24 deletions

View File

@ -20,5 +20,5 @@ package common
import "go.etcd.io/etcd/tests/v3/framework" import "go.etcd.io/etcd/tests/v3/framework"
func init() { func init() {
testFramework = framework.RunE2eTests testRunner = framework.E2eTestRunner
} }

View File

@ -22,5 +22,5 @@ import (
) )
func init() { func init() {
testFramework = framework.RunIntegrationTests testRunner = framework.IntegrationTestRunner
} }

View File

@ -22,8 +22,8 @@ import (
) )
func TestKVPut(t *testing.T) { func TestKVPut(t *testing.T) {
testFramework.BeforeTest(t) testRunner.BeforeTest(t)
clus := testFramework.NewCluster(t) clus := testRunner.NewCluster(t)
defer clus.Close() defer clus.Close()
cc := clus.Client() cc := clus.Client()

View File

@ -20,8 +20,8 @@ import (
"go.etcd.io/etcd/tests/v3/framework" "go.etcd.io/etcd/tests/v3/framework"
) )
var testFramework = framework.TestFramework var testRunner = framework.UnitTestRunner
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
testFramework.TestMain(m) testRunner.TestMain(m)
} }

View File

@ -24,9 +24,9 @@ import (
"go.etcd.io/etcd/tests/v3/framework/testutils" "go.etcd.io/etcd/tests/v3/framework/testutils"
) )
type e2eFramework struct{} type e2eRunner struct{}
func (e e2eFramework) TestMain(m *testing.M) { func (e e2eRunner) TestMain(m *testing.M) {
e2e.InitFlags() e2e.InitFlags()
v := m.Run() v := m.Run()
if v == 0 && testutil.CheckLeakedGoroutine() { if v == 0 && testutil.CheckLeakedGoroutine() {
@ -35,11 +35,11 @@ func (e e2eFramework) TestMain(m *testing.M) {
os.Exit(v) os.Exit(v)
} }
func (e e2eFramework) BeforeTest(t testing.TB) { func (e e2eRunner) BeforeTest(t testing.TB) {
e2e.BeforeTest(t) e2e.BeforeTest(t)
} }
func (e e2eFramework) NewCluster(t testing.TB) Cluster { func (e e2eRunner) NewCluster(t testing.TB) Cluster {
epc, err := e2e.NewEtcdProcessCluster(t, e2e.ConfigStandalone(*e2e.NewConfigAutoTLS())) epc, err := e2e.NewEtcdProcessCluster(t, e2e.ConfigStandalone(*e2e.NewConfigAutoTLS()))
if err != nil { if err != nil {
t.Fatalf("could not start etcd integrationCluster: %s", err) t.Fatalf("could not start etcd integrationCluster: %s", err)

View File

@ -15,7 +15,10 @@
package framework package framework
var ( var (
TestFramework testFramework = noFrameworkSelected{} // UnitTestRunner only runs in `--short` mode, will fail otherwise. Attempts in cluster creation will result in tests being skipped.
RunE2eTests testFramework = e2eFramework{} UnitTestRunner testRunner = unitRunner{}
RunIntegrationTests testFramework = integrationFramework{} // E2eTestRunner runs etcd and etcdctl binaries in a separate process.
E2eTestRunner = e2eRunner{}
// IntegrationTestRunner runs etcdserver.EtcdServer in separate goroutine and uses client libraries to communicate.
IntegrationTestRunner = integrationRunner{}
) )

View File

@ -24,17 +24,17 @@ import (
"go.etcd.io/etcd/tests/v3/framework/testutils" "go.etcd.io/etcd/tests/v3/framework/testutils"
) )
type integrationFramework struct{} type integrationRunner struct{}
func (e integrationFramework) TestMain(m *testing.M) { func (e integrationRunner) TestMain(m *testing.M) {
testutil.MustTestMainWithLeakDetection(m) testutil.MustTestMainWithLeakDetection(m)
} }
func (e integrationFramework) BeforeTest(t testing.TB) { func (e integrationRunner) BeforeTest(t testing.TB) {
integration.BeforeTest(t) integration.BeforeTest(t)
} }
func (e integrationFramework) NewCluster(t testing.TB) Cluster { func (e integrationRunner) NewCluster(t testing.TB) Cluster {
return &integrationCluster{ return &integrationCluster{
Cluster: integration.NewCluster(t, &integration.ClusterConfig{Size: 1}), Cluster: integration.NewCluster(t, &integration.ClusterConfig{Size: 1}),
t: t, t: t,

View File

@ -21,7 +21,7 @@ import (
"go.etcd.io/etcd/tests/v3/framework/testutils" "go.etcd.io/etcd/tests/v3/framework/testutils"
) )
type testFramework interface { type testRunner interface {
TestMain(m *testing.M) TestMain(m *testing.M)
BeforeTest(testing.TB) BeforeTest(testing.TB)
NewCluster(testing.TB) Cluster NewCluster(testing.TB) Cluster

View File

@ -23,11 +23,11 @@ import (
"go.etcd.io/etcd/client/pkg/v3/testutil" "go.etcd.io/etcd/client/pkg/v3/testutil"
) )
type noFrameworkSelected struct{} type unitRunner struct{}
var _ testFramework = (*noFrameworkSelected)(nil) var _ testRunner = (*unitRunner)(nil)
func (e noFrameworkSelected) TestMain(m *testing.M) { func (e unitRunner) TestMain(m *testing.M) {
flag.Parse() flag.Parse()
if !testing.Short() { if !testing.Short() {
fmt.Println(`No test mode selected, please selected either e2e mode with "--tags e2e" or integration mode with "--tags integration"`) fmt.Println(`No test mode selected, please selected either e2e mode with "--tags e2e" or integration mode with "--tags integration"`)
@ -35,10 +35,10 @@ func (e noFrameworkSelected) TestMain(m *testing.M) {
} }
} }
func (e noFrameworkSelected) BeforeTest(t testing.TB) { func (e unitRunner) BeforeTest(t testing.TB) {
testutil.SkipTestIfShortMode(t, "Cannot create clusters in --short tests")
} }
func (e noFrameworkSelected) NewCluster(t testing.TB) Cluster { func (e unitRunner) NewCluster(t testing.TB) Cluster {
testutil.SkipTestIfShortMode(t, "Cannot create clusters in --short tests")
return nil return nil
} }