Skip to content

Chore/tests linting#60

Merged
hyp3rd merged 4 commits intomainfrom
chore/tests-linting
Jan 17, 2026
Merged

Chore/tests linting#60
hyp3rd merged 4 commits intomainfrom
chore/tests-linting

Conversation

@hyp3rd
Copy link
Owner

@hyp3rd hyp3rd commented Jan 17, 2026

No description provided.

- Update go.mod to use hyperlogger v0.1.1 (from v0.1.0)
- Refresh go.sum checksums accordingly
- Enable tests in golangci-lint (.golangci.yaml) and expand allowed integer literals (e.g., 0o004).
- Replace magic numbers in tests with named constants (e.g., base64MaxLength, writeMaxSize, readMaxSize, backupCodeCount, longInputLength, keyLength).
- Update option usage to rely on these constants (WithBase64MaxLength/WithHexMaxLength/WithJSONMaxBytes, WithWriteMaxSize/WithReadMaxSize, WithBackupCodeCount).
- Prefer t.Fatal over t.Fatalf where formatting is unnecessary; add targeted nolint comments for intentional values.
- Clarify boundary/invalid cases in HOTP/TOTP tests; minor cleanups across encoding, io, memory, mfa, password, sanitize, secrets, tokens, and validate packages.
- No production code changes; tests and lint config only.
Copilot AI review requested due to automatic review settings January 17, 2026 19:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses linting issues in test files by enabling linting for tests and fixing various violations. The changes focus on improving test code quality through constant extraction, appropriate use of t.Fatal vs t.Fatalf, and adding nolint directives where necessary.

Changes:

  • Enabled linting for test files in .golangci.yaml and added 0o004 to allowed integers
  • Extracted magic numbers and repeated values into named constants across test files
  • Corrected usage of t.Fatal() vs t.Fatalf() based on whether format arguments are present
  • Added //nolint:revive directives to suppress specific linting warnings for unavoidable violations
  • Updated hyperlogger dependency from v0.1.0 to v0.1.1

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
.golangci.yaml Enabled linting for test files and added 0o004 to allowed integers
go.mod Updated hyperlogger dependency to v0.1.1
go.sum Updated checksums for hyperlogger v0.1.1
pkg/validate/url_test.go Added nolint directive for validator variable
pkg/tokens/tokens_test.go Added nolint directives for validator and token variables
pkg/secrets/secrets_test.go Extracted longInputLength constant, fixed t.Fatal usage
pkg/sanitize/filename_test.go Added nolint directive for sanitizer variable
pkg/password/argon2id_test.go Extracted keyLength constant
pkg/mfa/totp_test.go Extracted invalidValue constant, fixed t.Fatal usage
pkg/mfa/hotp_test.go Extracted counter and resync constants, removed duplicate variable declarations, fixed t.Fatal usage
pkg/mfa/backup_test.go Extracted backupCodeCount constant, improved error message formatting
pkg/memory/reader_test.go Added nolint directive
pkg/io/file_test.go References writeMaxSize constant from copy_test.go
pkg/io/copy_test.go Defined writeMaxSize constant
pkg/encoding/encoding_test.go Extracted base64MaxLength constant (used for multiple purposes)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

filename := filepath.Base(uniqueTempPath(t, "sectools-reader-max-"))

client, err := NewWithOptions(WithWriteMaxSize(3))
client, err := NewWithOptions(WithWriteMaxSize(writeMaxSize))
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The constant writeMaxSize is used here but is not defined in this file. It appears to be defined in pkg/io/copy_test.go. Since test files in the same package can share constants, this will work, but it creates a confusing dependency between test files. Consider defining this constant in this file as well, or moving shared test constants to a common test helper file.

Suggested change
client, err := NewWithOptions(WithWriteMaxSize(writeMaxSize))
client, err := NewWithOptions(WithWriteMaxSize(readMaxSize))

Copilot uses AI. Check for mistakes.
Comment on lines +175 to +179
opts: []HOTPOption{WithHOTPDigits(Digits(invalidValue))},
},
{
name: "invalid-algorithm",
opts: []HOTPOption{WithHOTPAlgorithm(Algorithm(99))},
opts: []HOTPOption{WithHOTPAlgorithm(Algorithm(invalidValue))},
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The constant invalidValue is used here but is not defined in this file. It appears to be defined in pkg/mfa/totp_test.go. Since test files in the same package can share constants, this will work, but it creates a confusing dependency between test files. Consider defining this constant in this file as well, or moving shared test constants to a common location in the package.

Copilot uses AI. Check for mistakes.

const errMsgUnexpected = "expected decoded, got %v"

const base64MaxLength = 4
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

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

The constant name base64MaxLength is misleading because it's also used for hex encoding and JSON decoding limits. Consider renaming to a more generic name like maxLengthForTest or smallMaxLength, or create separate constants with appropriate names for each use case.

Copilot uses AI. Check for mistakes.
Update .pre-commit-config.yaml to use yamllint v1.38.0 (from v1.37.1).
Keeps lint tooling current; may surface new lint warnings, no runtime changes.
@hyp3rd hyp3rd merged commit 7baf7a9 into main Jan 17, 2026
13 checks passed
@hyp3rd hyp3rd deleted the chore/tests-linting branch January 17, 2026 20:02
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.

1 participant