Add comprehensive test coverage for token generator/validator#41
Add comprehensive test coverage for token generator/validator#41hyp3rd merged 3 commits intofeat/tokensfrom
Conversation
Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This pull request adds comprehensive test coverage for the token generator/validator package to address gaps identified in PR #40. The tests validate error handling for edge cases, configuration validation, encoding formats, and cryptographic randomness.
Changes:
- Added 15 new test functions covering empty/whitespace validation, invalid encoding formats, raw byte generation, invalid configuration values, token randomness, and invalid encoding enums
- Added
bytespackage import for efficient byte slice comparison in randomness tests
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| t.Fatalf("expected generator, got %v", err) | ||
| } | ||
|
|
||
| bytes, err := generator.GenerateBytes() |
There was a problem hiding this comment.
Variable name 'bytes' shadows the imported 'bytes' package. Consider renaming to 'data', 'result', or 'tokenBytes' to avoid confusion and potential issues if the bytes package methods need to be used later in this function.
| t.Fatalf("expected generator, got %v", err) | ||
| } | ||
|
|
||
| bytes, err := generator.GenerateBytes() |
There was a problem hiding this comment.
Variable name 'bytes' shadows the imported 'bytes' package. Consider renaming to 'data', 'result', or 'tokenBytes' to avoid confusion and potential issues if the bytes package methods need to be used later in this function.
Addresses missing test scenarios in the token package identified during code review of PR #40.
Added Test Coverage
ErrTokenEmptyfor empty and whitespace-only inputsminBytesconfigurationsminEntropyBits,minBytes, andmaxLengthreturnErrInvalidTokenConfigTokenEncodingvaluesAll tests follow existing package patterns and use
bytes.Equal()for efficient byte comparison.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.