From 26f527ef64b552ad08940e63b92eef005021a804 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 20 Jan 2025 09:07:42 +0100 Subject: [PATCH] Fix incorrect TestingT.Errorf usage and enable linting for this (#2182) ## Changes - Fix incorrect use Errorf on literal string. This resulted in garbage output in tests diagnostics where % was replaced by "(MISSING)". - Enable linter on testingT.Errorf. Note, the autofix by the linter is wrong, it proposes `t.Errorf("%s", string)` but it should be `t.Error(string)`. That can corrected manually though. ## Tests Linter was tested manually by reverting the fix on Errorf. --- .golangci.yaml | 7 +++++++ libs/testdiff/testdiff.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.golangci.yaml b/.golangci.yaml index ea6d65db1..8a83135ee 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -22,6 +22,13 @@ linters-settings: disable: - fieldalignment - shadow + settings: + printf: + funcs: + - (github.com/databricks/cli/internal/testutil.TestingT).Infof + - (github.com/databricks/cli/internal/testutil.TestingT).Errorf + - (github.com/databricks/cli/internal/testutil.TestingT).Fatalf + - (github.com/databricks/cli/internal/testutil.TestingT).Skipf gofmt: rewrite-rules: - pattern: 'a[b:len(a)]' diff --git a/libs/testdiff/testdiff.go b/libs/testdiff/testdiff.go index 232f38b41..f65adf7f7 100644 --- a/libs/testdiff/testdiff.go +++ b/libs/testdiff/testdiff.go @@ -26,7 +26,7 @@ func AssertEqualTexts(t testutil.TestingT, filename1, filename2, expected, out s // only show diff for large texts diff := UnifiedDiff(filename1, filename2, expected, out) if diff != "" { - t.Errorf("Diff:\n" + diff) + t.Error("Diff:\n" + diff) return false } }