Skip to content

Commit

Permalink
Fix incorrect TestingT.Errorf usage and enable linting for this (#2182)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
denik authored Jan 20, 2025
1 parent 50f6269 commit 26f527e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)]'
Expand Down
2 changes: 1 addition & 1 deletion libs/testdiff/testdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 26f527e

Please sign in to comment.