Skip to content

Commit

Permalink
tests: Rename framework to runner and document the runners
Browse files Browse the repository at this point in the history
  • Loading branch information
serathius committed Feb 23, 2022
1 parent c3f20c6 commit 919a925
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion tests/common/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ package common
import "go.etcd.io/etcd/tests/v3/framework"

func init() {
testFramework = framework.RunE2eTests
testRunner = framework.E2eTestRunner
}
2 changes: 1 addition & 1 deletion tests/common/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ import (
)

func init() {
testFramework = framework.RunIntegrationTests
testRunner = framework.IntegrationTestRunner
}
4 changes: 2 additions & 2 deletions tests/common/kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

func TestKVPut(t *testing.T) {
testFramework.BeforeTest(t)
clus := testFramework.NewCluster(t)
testRunner.BeforeTest(t)
clus := testRunner.NewCluster(t)
defer clus.Close()
cc := clus.Client()

Expand Down
4 changes: 2 additions & 2 deletions tests/common/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"go.etcd.io/etcd/tests/v3/framework"
)

var testFramework = framework.TestFramework
var testRunner = framework.UnitTestRunner

func TestMain(m *testing.M) {
testFramework.TestMain(m)
testRunner.TestMain(m)
}
8 changes: 4 additions & 4 deletions tests/framework/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"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()
v := m.Run()
if v == 0 && testutil.CheckLeakedGoroutine() {
Expand All @@ -35,11 +35,11 @@ func (e e2eFramework) TestMain(m *testing.M) {
os.Exit(v)
}

func (e e2eFramework) BeforeTest(t testing.TB) {
func (e e2eRunner) BeforeTest(t testing.TB) {
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()))
if err != nil {
t.Fatalf("could not start etcd integrationCluster: %s", err)
Expand Down
9 changes: 6 additions & 3 deletions tests/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
package framework

var (
TestFramework testFramework = noFrameworkSelected{}
RunE2eTests testFramework = e2eFramework{}
RunIntegrationTests testFramework = integrationFramework{}
// UnitTestRunner only runs in `--short` mode, will fail otherwise. Attempts in cluster creation will result in tests being skipped.
UnitTestRunner = unitRunner{}
// 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{}
)
8 changes: 4 additions & 4 deletions tests/framework/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import (
"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)
}

func (e integrationFramework) BeforeTest(t testing.TB) {
func (e integrationRunner) BeforeTest(t testing.TB) {
integration.BeforeTest(t)
}

func (e integrationFramework) NewCluster(t testing.TB) Cluster {
func (e integrationRunner) NewCluster(t testing.TB) Cluster {
return &integrationCluster{
Cluster: integration.NewCluster(t, &integration.ClusterConfig{Size: 1}),
t: t,
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"go.etcd.io/etcd/tests/v3/framework/testutils"
)

type testFramework interface {
type testRunner interface {
TestMain(m *testing.M)
BeforeTest(testing.TB)
NewCluster(testing.TB) Cluster
Expand Down
12 changes: 6 additions & 6 deletions tests/framework/default.go → tests/framework/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ import (
"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()
if !testing.Short() {
fmt.Println(`No test mode selected, please selected either e2e mode with "--tags e2e" or integration mode with "--tags integration"`)
os.Exit(1)
}
}

func (e noFrameworkSelected) BeforeTest(t testing.TB) {
testutil.SkipTestIfShortMode(t, "Cannot create clusters in --short tests")
func (e unitRunner) BeforeTest(t testing.TB) {
}

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
}

0 comments on commit 919a925

Please sign in to comment.