From 7892d942528279f8cd6834cba9f73a7c90334fcd Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 29 Dec 2025 13:26:58 +0100 Subject: [PATCH] acc: add TESTLOG feature If output lines are prefixed with "TESTLOG: " they will be logged but not recorded in the output. This is similar to LOG* feature but it logs lines are they come which more useful for debugging log-running tests. --- acceptance/acceptance_test.go | 22 ++++++++++++++++++---- acceptance/selftest/testlog/out.test.toml | 5 +++++ acceptance/selftest/testlog/output.txt | 0 acceptance/selftest/testlog/script | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 acceptance/selftest/testlog/out.test.toml create mode 100644 acceptance/selftest/testlog/output.txt create mode 100644 acceptance/selftest/testlog/script diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 475401711f..cb6c8bd39d 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -60,6 +60,9 @@ var ( // Also disables parallelism in tests. var InprocessMode bool +// lines with this prefix are not recorded in output.txt but logged instead +const TestLogPrefix = "TESTLOG: " + func init() { flag.BoolVar(&InprocessMode, "inprocess", false, "Run CLI in the same process as test (for debugging)") flag.BoolVar(&KeepTmp, "keeptmp", false, "Do not delete TMP directory after run") @@ -1275,14 +1278,20 @@ func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) (string, e if tail { msg := strings.TrimRight(line, "\n") if len(msg) > 0 { - d := time.Since(start) - t.Logf("%2d.%03d %s", d/time.Second, (d%time.Second)/time.Millisecond, msg) + logWithDurationSince(t, start, msg) } } if len(line) > 0 { mostRecentLine = line - _, err = out.WriteString(line) - require.NoError(t, err) + if strings.HasPrefix(line, TestLogPrefix) { + // if tail is true, we already logged it above + if !tail { + logWithDurationSince(t, start, strings.TrimRight(line, "\n")) + } + } else { + _, err = out.WriteString(line) + require.NoError(t, err) + } } if err == io.EOF { break @@ -1299,6 +1308,11 @@ func runWithLog(t *testing.T, cmd *exec.Cmd, out *os.File, tail bool) (string, e return skipReason, <-processErrCh } +func logWithDurationSince(t *testing.T, start time.Time, msg string) { + d := time.Since(start) + t.Logf("%2d.%03d %s", d/time.Second, (d%time.Second)/time.Millisecond, msg) +} + func getCloudEnvBase(cloudEnv string) string { switch cloudEnv { // no idea why, but diff --git a/acceptance/selftest/testlog/out.test.toml b/acceptance/selftest/testlog/out.test.toml new file mode 100644 index 0000000000..d560f1de04 --- /dev/null +++ b/acceptance/selftest/testlog/out.test.toml @@ -0,0 +1,5 @@ +Local = true +Cloud = false + +[EnvMatrix] + DATABRICKS_BUNDLE_ENGINE = ["terraform", "direct"] diff --git a/acceptance/selftest/testlog/output.txt b/acceptance/selftest/testlog/output.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/acceptance/selftest/testlog/script b/acceptance/selftest/testlog/script new file mode 100644 index 0000000000..c7c2fb0a23 --- /dev/null +++ b/acceptance/selftest/testlog/script @@ -0,0 +1 @@ +echo "TESTLOG: this is logged, not saved to output.txt"