From 35c4b92e92d14d9479296b831d098ba1aed3a2b7 Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Mon, 18 May 2015 12:11:33 -0700 Subject: [PATCH] Make e2e compatible with Go 1.3 and OS X. Go 1.4 added the -o flag to the "go test" command as well as support for the TestMain() function, so we must work around these not existing in Go 1.3. The version of readlink on OS X does not have the -f flag - so we'll just skip canonicalizing the path. --- hack/ginkgo-e2e.sh | 2 +- hack/lib/golang.sh | 6 +++++- test/e2e/e2e_test.go | 38 ++++++++++++++------------------------ 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/hack/ginkgo-e2e.sh b/hack/ginkgo-e2e.sh index a2bba55b24..6b5013420b 100755 --- a/hack/ginkgo-e2e.sh +++ b/hack/ginkgo-e2e.sh @@ -19,7 +19,7 @@ set -o nounset set -o pipefail GINKGO_PARALLEL=${GINKGO_PARALLEL:-n} # set to 'y' to run tests in parallel -KUBE_ROOT=$(readlink -f $(dirname "${BASH_SOURCE}")/..) +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. source "${KUBE_ROOT}/cluster/common.sh" source "${KUBE_ROOT}/hack/lib/init.sh" diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index f81579b241..b0d2a40d23 100644 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -361,10 +361,14 @@ kube::golang::build_binaries_for_platform() { for test in "${tests[@]:+${tests[@]}}"; do local outfile=$(kube::golang::output_filename_for_binary "${test}" \ "${platform}") - go test -c -o "${outfile}" \ + # Go 1.4 added -o to control where the binary is saved, but Go 1.3 doesn't + # have this flag. Whenever we deprecate go 1.3, update to use -o instead of + # calling mv. + go test -c \ "${goflags[@]:+${goflags[@]}}" \ -ldflags "${version_ldflags}" \ "$(dirname ${test})" + mv -f "$(basename ${outfile})" "${outfile}" done } diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 8b2523e2fa..4d8e134f21 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -19,9 +19,7 @@ package e2e import ( "flag" "fmt" - "os" "path" - goruntime "runtime" "strings" "testing" @@ -65,32 +63,13 @@ func init() { } func TestE2E(t *testing.T) { - defer util.FlushLogs() - - // Disable density test unless it's explicitly requested. - if config.GinkgoConfig.FocusString == "" && config.GinkgoConfig.SkipString == "" { - config.GinkgoConfig.SkipString = "Skipped" - } - - gomega.RegisterFailHandler(ginkgo.Fail) - // Run tests through the Ginkgo runner with output to console + JUnit for Jenkins - var r []ginkgo.Reporter - if *reportDir != "" { - r = append(r, reporters.NewJUnitReporter(path.Join(*reportDir, fmt.Sprintf("junit_%02d.xml", config.GinkgoConfig.ParallelNode)))) - } - ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r) -} - -func TestMain(m *testing.M) { - flag.Parse() util.ReallyCrash = true util.InitLogs() - goruntime.GOMAXPROCS(goruntime.NumCPU()) + defer util.FlushLogs() // TODO: possibly clean up or refactor this functionality. if testContext.Provider == "" { - glog.Info("The --provider flag is not set. Treating as a conformance test. Some tests may not be run.") - os.Exit(1) + glog.Fatal("The --provider flag is not set. Treating as a conformance test. Some tests may not be run.") } if testContext.Provider == "aws" { @@ -107,5 +86,16 @@ func TestMain(m *testing.M) { } } - os.Exit(m.Run()) + // Disable density test unless it's explicitly requested. + if config.GinkgoConfig.FocusString == "" && config.GinkgoConfig.SkipString == "" { + config.GinkgoConfig.SkipString = "Skipped" + } + + gomega.RegisterFailHandler(ginkgo.Fail) + // Run tests through the Ginkgo runner with output to console + JUnit for Jenkins + var r []ginkgo.Reporter + if *reportDir != "" { + r = append(r, reporters.NewJUnitReporter(path.Join(*reportDir, fmt.Sprintf("junit_%02d.xml", config.GinkgoConfig.ParallelNode)))) + } + ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "Kubernetes e2e suite", r) }