From b0706ccdc129291714d46de408fbed4c7baca733 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Thu, 9 Jan 2025 10:00:05 +0100 Subject: [PATCH] Use -update instead of TESTS_OUTPUT=OVERWRITE (#2097) It's easier to remember and type and also validated and part of help: ``` % go test ./acceptance -updat 2>&1 | grep updat flag provided but not defined: -updat -update ``` --- acceptance/README.md | 2 +- libs/testdiff/golden.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/acceptance/README.md b/acceptance/README.md index 162c57ea2..42a37d253 100644 --- a/acceptance/README.md +++ b/acceptance/README.md @@ -9,7 +9,7 @@ To author a test, The test runner will run script and capture output and compare it with `output.txt` file in the same directory. -In order to write `output.txt` for the first time or overwrite it with the current output, set `TESTS_OUTPUT=OVERWRITE` env var. +In order to write `output.txt` for the first time or overwrite it with the current output pass -update flag to go test. The scripts are run with `bash -e` so any errors will be propagated. They are captured in `output.txt` by appending `Exit code: N` line at the end. diff --git a/libs/testdiff/golden.go b/libs/testdiff/golden.go index b67eb50a9..02213c88a 100644 --- a/libs/testdiff/golden.go +++ b/libs/testdiff/golden.go @@ -2,6 +2,7 @@ package testdiff import ( "context" + "flag" "fmt" "os" "regexp" @@ -16,7 +17,11 @@ import ( "github.com/stretchr/testify/assert" ) -var OverwriteMode = os.Getenv("TESTS_OUTPUT") == "OVERWRITE" +var OverwriteMode = false + +func init() { + flag.BoolVar(&OverwriteMode, "update", false, "Overwrite golden files") +} func ReadFile(t testutil.TestingT, ctx context.Context, filename string) string { t.Helper()