Skip to content

Conversation

@kolyshkin
Copy link
Contributor

This is a followup to #1476, inspired by #1476 (comment).

See individual commits for details.

This suppresses the following staticcheck warnings in tests:

hooks/test/test_test.go:76:2: SA4006: this value of assert is never used (staticcheck)
	assert := assert.New(t)
	^
hooks/test/test_test.go:78:2: SA4006: this value of hook is never used (staticcheck)
	logger, hook := NewNullLogger()
	^

...and fixes the following staticcheck and unparam warnings in tests:

json_formatter_test.go:232:5: QF1001: could apply De Morgan's law (staticcheck)
	if !(strings.Contains(s, "message") && strings.Contains(s, "oh hai")) {
	   ^
json_formatter_test.go:369:5: QF1001: could apply De Morgan's law (staticcheck)
	if !(strings.Contains(s, "u0026") && strings.Contains(s, "u003e") && strings.Contains(s, "u003c")) {
	   ^
hooks/test/test_test.go:96:11: TestNewLocal$1 - i is unused (unparam)
		go func(i int) {
		        ^

Signed-off-by: Kir Kolyshkin <[email protected]>
Mostly generated with golangci-lint run --fix ./...

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin kolyshkin changed the title Enable linting test files ci: enable linting test files Jan 21, 2026
Copy link
Collaborator

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good; left two suggestions; let me know what you think

Comment on lines -369 to 371
if !(strings.Contains(s, "u0026") && strings.Contains(s, "u003e") && strings.Contains(s, "u003c")) {
if !strings.Contains(s, "u0026") || !strings.Contains(s, "u003e") || !strings.Contains(s, "u003c") {
t.Error("Message should be HTML escaped", s)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we should have a predictable output here, so we can just match the escaped sequence for & < >;

Suggested change
if !(strings.Contains(s, "u0026") && strings.Contains(s, "u003e") && strings.Contains(s, "u003c")) {
if !strings.Contains(s, "u0026") || !strings.Contains(s, "u003e") || !strings.Contains(s, "u003c") {
t.Error("Message should be HTML escaped", s)
}
if !strings.Contains(s, `\u0026 \u003c \u003e`) {
t.Error("Message should be HTML escaped", s)
}

Comment on lines -232 to 233
if !(strings.Contains(s, "message") && strings.Contains(s, "oh hai")) {
if !strings.Contains(s, "message") || !strings.Contains(s, "oh hai") {
t.Fatal("Expected JSON to format message key")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this one; I expect the JSON format to be stable enough;

Suggested change
if !(strings.Contains(s, "message") && strings.Contains(s, "oh hai")) {
if !strings.Contains(s, "message") || !strings.Contains(s, "oh hai") {
t.Fatal("Expected JSON to format message key")
if !strings.Contains(s, `"message":"oh hai"`) {
t.Fatal("Expected JSON to format message key", s)
}

FWIW; output here looks to be {"level":"panic","message":"oh hai","time":"0001-01-01T00:00:00Z"} so possibly we could even do a straight compare for the whole message, but either way is probably fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants