From 6a79d4e2659d216282521324028563536aac226b Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Thu, 15 Jan 2015 16:11:46 -0800 Subject: [PATCH] Support a --test/-t repeated flag to allow run only a subset of the e2e.go tests. This syntax is akin to what Python unittest uses for running a subset of the tests. If a test gets skipped, log it. If an invalid test test is passed to --test, warn about it. --- cmd/e2e/e2e.go | 7 ++++++- test/e2e/driver.go | 23 ++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cmd/e2e/e2e.go b/cmd/e2e/e2e.go index 9c9141c85f3..24f1688ad96 100644 --- a/cmd/e2e/e2e.go +++ b/cmd/e2e/e2e.go @@ -30,10 +30,15 @@ var ( certDir = flag.String("cert_dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.") host = flag.String("host", "", "The host to connect to") repoRoot = flag.String("repo_root", "./", "Root directory of kubernetes repository, for finding test files. Default assumes working directory is repository root") + testList util.StringList ) +func init() { + flag.VarP(&testList, "test", "t", "Test to execute (may be repeated or comma separated list of tests.) Defaults to running all tests.") +} + func main() { util.InitFlags() goruntime.GOMAXPROCS(goruntime.NumCPU()) - e2e.RunE2ETests(*authConfig, *certDir, *host, *repoRoot) + e2e.RunE2ETests(*authConfig, *certDir, *host, *repoRoot, testList) } diff --git a/test/e2e/driver.go b/test/e2e/driver.go index 8b4c91011af..365726c8ef5 100644 --- a/test/e2e/driver.go +++ b/test/e2e/driver.go @@ -51,7 +51,7 @@ func outputTAPSummary(infoList []testInfo) { } } -func RunE2ETests(authConfig, certDir, host, repoRoot string) { +func RunE2ETests(authConfig, certDir, host, repoRoot string, testList []string) { testContext = testContextType{authConfig, certDir, host, repoRoot} util.ReallyCrash = true util.InitLogs() @@ -77,9 +77,30 @@ func RunE2ETests(authConfig, certDir, host, repoRoot string) { {TestBasic, "TestBasic", 8}, } + validTestNames := util.NewStringSet() + for _, test := range tests { + validTestNames.Insert(test.name) + } + + // Check testList for non-existent tests and populate a StringSet with tests to run. + runTestNames := util.NewStringSet() + for _, testName := range testList { + if validTestNames.Has(testName) { + runTestNames.Insert(testName) + } else { + glog.Warningf("Requested test %s does not exist", testName) + } + } + info := []testInfo{} passed := true for i, test := range tests { + // Check if this test is supposed to run, either if listed explicitly in + // a --test flag or if no --test flags were supplied. + if len(testList) > 0 && !runTestNames.Has(test.name) { + glog.Infof("Skipping test %d %s", i+1, test.name) + continue + } glog.Infof("Running test %d %s", i+1, test.name) testPassed := test.test(c) if !testPassed {