From f7864977b6dad020fd3b3ec2f40aa0a3188bff09 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 6 Sep 2022 15:51:26 +0200 Subject: [PATCH] e2e internal: support Ginkgo v2 log time stamps When using By or some other Ginkgo output functions, Ginkgo v2 now adds a time stamp at the end of the line that we need to ignore. Will become relevant when testing more complete output. --- test/e2e/framework/internal/output/output.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/e2e/framework/internal/output/output.go b/test/e2e/framework/internal/output/output.go index e167e05a0d1..0fc847b0141 100644 --- a/test/e2e/framework/internal/output/output.go +++ b/test/e2e/framework/internal/output/output.go @@ -29,7 +29,7 @@ import ( "k8s.io/kubernetes/test/e2e/framework" ) -func TestGinkgoOutput(t *testing.T, expected SuiteResults) { +func TestGinkgoOutput(t *testing.T, expected SuiteResults, runSpecsArgs ...interface{}) { // Run the Ginkgo suite with spec results collected via ReportAfterEach // in adddition to the default one. To see what the full // Ginkgo output looks like, run this test with "go test -v". @@ -39,7 +39,7 @@ func TestGinkgoOutput(t *testing.T, expected SuiteResults) { report = append(report, spec) }) fakeT := &testing.T{} - ginkgo.RunSpecs(fakeT, "Logging Suite") + ginkgo.RunSpecs(fakeT, "Logging Suite", runSpecsArgs...) // Now check the output. actual := normalizeReport(report) @@ -103,9 +103,13 @@ var timePrefix = regexp.MustCompile(`(?m)^[[:alpha:]]{3} +[[:digit:]]{1,2} +[[:d // elapsedSuffix matches "Elapsed: 16.189µs" var elapsedSuffix = regexp.MustCompile(`Elapsed: [[:digit:]]+(\.[[:digit:]]+)?(µs|ns|ms|s|m)`) +// timeSuffix matches "09/06/22 15:36:43.445" as printed by Ginkgo v2 for log output. +var timeSuffix = regexp.MustCompile(`(?m)[[:space:]][[:digit:]]{2}/[[:digit:]]{2}/[[:digit:]]{2} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}\.[[:digit:]]{1,3}$`) + func stripTimes(in string) string { out := timePrefix.ReplaceAllString(in, "") out = elapsedSuffix.ReplaceAllString(out, "Elapsed: ") + out = timeSuffix.ReplaceAllString(out, "") return out }