From 93d347442f7796f52bf611b6f5d10d4048d2d338 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Wed, 29 Jan 2020 14:52:34 -0600 Subject: [PATCH] e2e: add a -suite flag to e2e.Framework This change allows for providing the -suite= flag when running the e2e framework. If set, only the matching e2e/Framework.TestSuite.Component will be run, and all ther suites will be skipped. --- e2e/README.md | 11 +++++++++-- e2e/framework/framework.go | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/e2e/README.md b/e2e/README.md index 06be791d7..628193c65 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -81,10 +81,17 @@ cd .. go test -v . ``` +If you want to run a specific suite, you can specify the `-suite` flag as +shown below. Only the suite with a matching `Framework.TestSuite.Component` +will be run, and all others will be skipped. +```sh +go test -v -suite=Consul . +``` + If you want to run a specific test, you'll need to regex-escape some of the test's name so that the test runner doesn't skip over framework struct method names in the full name of the tests: ```sh - go test -v . -run 'TestE2E/Consul/\*consul\.ScriptChecksE2ETest/TestGroup' - ``` +go test -v . -run 'TestE2E/Consul/\*consul\.ScriptChecksE2ETest/TestGroup' +``` diff --git a/e2e/framework/framework.go b/e2e/framework/framework.go index 73cd8adb5..241d824ff 100644 --- a/e2e/framework/framework.go +++ b/e2e/framework/framework.go @@ -20,6 +20,7 @@ These flags are coarse overrides for the test environment. -local force default no-op provisioning -skipTests skips all tests and only provisions -slow include execution of slow test suites + -suite run specified test suite -showHelp shows this help text Provisioning flags tell the test runner to pre-provision the cluster before @@ -58,6 +59,7 @@ var fSlow = flag.Bool("slow", false, "toggles execution of slow test suites") var fForceRun = flag.Bool("forceRun", false, "if set, skips all environment checks when filtering test suites") var fSkipTests = flag.Bool("skipTests", false, "skip all tests and only provision") +var fSuite = flag.String("suite", "", "run specified test suite") // Provisioning flags var fProvisionVagrant = flag.String("provision.vagrant", "", @@ -102,6 +104,7 @@ type Framework struct { slow bool force bool skipAll bool + suite string } // Environment contains information about the test target environment, used @@ -144,6 +147,7 @@ func New() *Framework { slow: *fSlow, force: *fForceRun, skipAll: *fSkipTests, + suite: *fSuite, } } @@ -215,6 +219,11 @@ func (f *Framework) runSuite(t *testing.T, s *TestSuite) (skip bool, err error) } } + // If -suite is set, skip any suite that is not the one specified. + if f.suite != "" && f.suite != s.Component { + return true, fmt.Errorf("only running suite %q", f.suite) + } + info, err := f.provisioner.SetupTestSuite(t, provisioning.SetupOptions{ Name: s.Component, ExpectConsul: s.Consul,