refactor: move URL normalization to shared package#26
Conversation
- Create shared/url package with NormalizeURL, HasScheme, and TrimTrailingSlashes functions - Update jtk to use shared URL normalization in config, API client, and config command - Remove duplicate NormalizeURL from jtk/internal/config - Remove duplicate hasScheme and trimTrailingSlash from jtk/api Note: cfl's NormalizeURL is different (adds /wiki suffix for Confluence) so it remains in place. Closes #14
Test Coverage Assessment for PR #26SummaryThis PR extracts URL normalization utilities from New Code:
|
| Function | Coverage | Assessment |
|---|---|---|
NormalizeURL |
100% | Fully covered with 9 test cases |
HasScheme |
100% | Fully covered with 6 test cases |
TrimTrailingSlashes |
100% | Fully covered with 5 test cases |
Test quality highlights:
- Empty string handling tested
- Both http:// and https:// schemes tested
- Single and multiple trailing slashes tested
- URLs with and without paths tested
- Edge cases like
ftp://andhttpx://schemes tested (should return false)
Changed Code: Consumers
The PR updates three files to use the shared package:
tools/jtk/api/client.go- Replaces inlinehasSchemeandtrimTrailingSlashwithurl.NormalizeURLtools/jtk/internal/config/config.go- Replaces localNormalizeURLwith shared versiontools/jtk/internal/cmd/configcmd/configcmd.go- Updates import path
Existing tests in config_test.go verify the integration works correctly through TestNormalizeURL (which now tests the shared package) and the various TestGetURL_* tests that exercise normalization in context.
Coverage Numbers
shared/url: 100% of statementsjtk/internal/config: 80.8% of statements (unchanged by this PR)jtk/api: 51.7% of statements (pre-existing - not affected by this refactor)
Verdict
Adequate coverage. The new shared package has 100% test coverage with comprehensive edge case testing. The refactoring is straightforward - extracting existing functionality into a shared location - and existing integration tests verify the wiring is correct. All tests pass.
No additional tests needed.
Summary
shared/urlpackage withNormalizeURL,HasScheme, andTrimTrailingSlashesfunctionsNormalizeURLfromjtk/internal/confighasSchemeandtrimTrailingSlashfromjtk/apiNotes
cfl's
NormalizeURLis different (adds/wikisuffix for Confluence) so it remains in place as a method onConfig.Test plan
Closes #14
🤖 Generated with Claude Code