From a9718f44cd6c938448fc697f0ec720ebed7d863a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 23 Dec 2020 19:47:20 +0100 Subject: [PATCH] para: Skip para test when not on CI Fixes #6963 --- common/para/para_test.go | 6 ++++++ htesting/test_helpers.go | 5 +++++ hugolib/hugo_modules_test.go | 6 +++--- hugolib/hugo_sites_build_errors_test.go | 3 ++- hugolib/hugo_sites_build_test.go | 2 +- hugolib/js_test.go | 4 ++-- hugolib/resource_chain_babel_test.go | 2 +- hugolib/resource_chain_test.go | 2 +- hugolib/testhelpers_test.go | 4 ---- 9 files changed, 21 insertions(+), 13 deletions(-) diff --git a/common/para/para_test.go b/common/para/para_test.go index 627528cf..646b7b36 100644 --- a/common/para/para_test.go +++ b/common/para/para_test.go @@ -22,6 +22,8 @@ import ( "testing" "time" + "github.com/gohugoio/hugo/htesting" + qt "github.com/frankban/quicktest" ) @@ -30,6 +32,10 @@ func TestPara(t *testing.T) { t.Skipf("skip para test, CPU count is %d", runtime.NumCPU()) } + if !htesting.IsCI() { + t.Skip("skip para test when not running on CI") + } + c := qt.New(t) c.Run("Order", func(c *qt.C) { diff --git a/htesting/test_helpers.go b/htesting/test_helpers.go index 84b36ee2..b584f4ca 100644 --- a/htesting/test_helpers.go +++ b/htesting/test_helpers.go @@ -15,6 +15,7 @@ package htesting import ( "math/rand" + "os" "runtime" "strings" "time" @@ -86,3 +87,7 @@ func DiffStringSlices(slice1 []string, slice2 []string) []string { func DiffStrings(s1, s2 string) []string { return DiffStringSlices(strings.Fields(s1), strings.Fields(s2)) } + +func IsCI() bool { + return (os.Getenv("CI") != "" || os.Getenv("CI_LOCAL") != "") && os.Getenv("CIRCLE_BRANCH") == "" +} diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go index 4946d0f5..fbb23232 100644 --- a/hugolib/hugo_modules_test.go +++ b/hugolib/hugo_modules_test.go @@ -41,7 +41,7 @@ import ( ) func TestHugoModulesVariants(t *testing.T) { - if !isCI() { + if !htesting.IsCI() { t.Skip("skip (relative) long running modules test when running locally") } @@ -285,12 +285,12 @@ JS imported in module: | // TODO(bep) this fails when testmodBuilder is also building ... func TestHugoModulesMatrix(t *testing.T) { - if !isCI() { + if !htesting.IsCI() { t.Skip("skip (relative) long running modules test when running locally") } t.Parallel() - if !isCI() || hugo.GoMinorVersion() < 12 { + if !htesting.IsCI() || hugo.GoMinorVersion() < 12 { // https://github.com/golang/go/issues/26794 // There were some concurrent issues with Go modules in < Go 12. t.Skip("skip this on local host and for Go <= 1.11 due to a bug in Go's stdlib") diff --git a/hugolib/hugo_sites_build_errors_test.go b/hugolib/hugo_sites_build_errors_test.go index 997aae56..efe013c3 100644 --- a/hugolib/hugo_sites_build_errors_test.go +++ b/hugolib/hugo_sites_build_errors_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/fortytw2/leaktest" + "github.com/gohugoio/hugo/htesting" qt "github.com/frankban/quicktest" "github.com/gohugoio/hugo/common/herrors" @@ -316,7 +317,7 @@ Some content. // https://github.com/gohugoio/hugo/issues/5375 func TestSiteBuildTimeout(t *testing.T) { - if !isCI() { + if !htesting.IsCI() { defer leaktest.CheckTimeout(t, 10*time.Second)() } diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 4d6a8697..fdfc33c5 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -414,7 +414,7 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) { func TestMultiSitesRebuild(t *testing.T) { // t.Parallel() not supported, see https://github.com/fortytw2/leaktest/issues/4 // This leaktest seems to be a little bit shaky on Travis. - if !isCI() { + if !htesting.IsCI() { defer leaktest.CheckTimeout(t, 10*time.Second)() } diff --git a/hugolib/js_test.go b/hugolib/js_test.go index 8d8e015a..a1b74a87 100644 --- a/hugolib/js_test.go +++ b/hugolib/js_test.go @@ -34,7 +34,7 @@ import ( ) func TestJSBuildWithNPM(t *testing.T) { - if !isCI() { + if !htesting.IsCI() { t.Skip("skip (relative) long running modules test when running locally") } @@ -142,7 +142,7 @@ function greeter(person) { } func TestJSBuild(t *testing.T) { - if !isCI() { + if !htesting.IsCI() { t.Skip("skip (relative) long running modules test when running locally") } diff --git a/hugolib/resource_chain_babel_test.go b/hugolib/resource_chain_babel_test.go index da03c83c..d5e99cd1 100644 --- a/hugolib/resource_chain_babel_test.go +++ b/hugolib/resource_chain_babel_test.go @@ -36,7 +36,7 @@ import ( ) func TestResourceChainBabel(t *testing.T) { - if !isCI() { + if !htesting.IsCI() { t.Skip("skip (relative) long running modules test when running locally") } diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index b5baa4d0..f8b1ccd4 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -826,7 +826,7 @@ Hello2: Bonjour } func TestResourceChainPostCSS(t *testing.T) { - if !isCI() { + if !htesting.IsCI() { t.Skip("skip (relative) long running modules test when running locally") } diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index 78d80beb..9e005d76 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -1032,10 +1032,6 @@ func printStringIndexes(s string) { } } -func isCI() bool { - return (os.Getenv("CI") != "" || os.Getenv("CI_LOCAL") != "") && os.Getenv("CIRCLE_BRANCH") == "" -} - // See https://github.com/golang/go/issues/19280 // Not in use. var parallelEnabled = true