refactor: adopt Go 1.26 features and clean up test temp files#477
refactor: adopt Go 1.26 features and clean up test temp files#477
Conversation
Use t.TempDir() for automatic temp directory cleanup in all cli/ test files. This removes manual defer os.Remove/os.RemoveAll calls and simplifies test setup by using os.WriteFile instead of CreateTemp + WriteString + Close patterns.
Fixes testifylint violations: error assertions must use require.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
There was a problem hiding this comment.
Pull request overview
This PR modernizes the codebase for Go 1.26 and simplifies test filesystem handling by switching to t.TempDir(), while adding coverage for stricter IPv6 URL parsing behavior affecting webhook validation.
Changes:
- Refactor reflection field iteration to use Go 1.26
reflect.Type.Fields()iterators. - Add webhook URL validation tests for bracketed vs unbracketed IPv6 URLs and whitelist behavior.
- Replace manual temp file/dir creation+cleanup in tests with
t.TempDir()patterns.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
core/common.go |
Update GetHash to iterate struct fields via t.Fields() (Go 1.26 iterator). |
config/validator.go |
Update validateStruct to iterate fields via typ.Fields() and skip unexported via IsExported(). |
middlewares/webhook_security_test.go |
Add IPv6 URL parsing + whitelist test cases aligned with stricter net/url parsing. |
middlewares/save_test.go |
Switch temp directory handling to t.TempDir() for save-folder creation test. |
core/localjob_comprehensive_test.go |
Replace manual temp dir lifecycle with t.TempDir() for working-directory execution test. |
core/adapters/docker/auth_test.go |
Use t.TempDir() for docker auth config fixture directories. |
cli/validate_test.go |
Use t.TempDir() + os.WriteFile for config fixtures (no manual cleanup). |
cli/daemon_lifecycle_test.go |
Use t.TempDir() + os.WriteFile for invalid config fixture. |
cli/daemon_full_lifecycle_test.go |
Use t.TempDir() + os.WriteFile for daemon boot config fixtures. |
cli/daemon_boot_test.go |
Use t.TempDir() + os.WriteFile and t.TempDir()-scoped missing-file paths. |
cli/config_test.go |
Replace temp file/dir creation with t.TempDir() for config file and glob tests. |
cli/config_show_test.go |
Replace temp file creation with t.TempDir() for config-show tests. |
cli/config_parsing_test.go |
Replace temp dir creation with t.TempDir() in config file resolution tests. |
cli/config_extra_test.go |
Replace temp file creation with t.TempDir() for INI reload/update tests. |
cli/config_comprehensive_test.go |
Replace temp dir creation with t.TempDir() for latest-changed test. |
.gitignore |
Ignore .worktrees/ directory. |
- Use portable t.TempDir() path instead of hardcoded /tmp for non-existent config file test case - Check os.WriteFile errors in resolveConfigFiles test setup
|
🚀 Released in v0.20.0 Thank you for your contribution! 🙏 This is now available in the latest release. Please test and verify everything works as expected in your environment. If you encounter any issues, please open a new issue. |
Summary
for i := range t.NumField()loops with Go 1.26reflect.Type.Fields()range iterator incore/common.go(GetHash) andconfig/validator.go(validateStruct), consistent with existing usage incli/config_decode.gonet/url.Parse()rejects unbracketed IPv6 addresses. Added tests verifying webhook URL validation handles both valid (bracketed) and invalid (unbracketed) IPv6 forms, plus whitelist matchingt.TempDir()which handles cleanup automatically. Net reduction of ~100 linesTest Plan
go build ./...passesgo vet ./...passesgolangci-lint run— 0 issuesgo test -race ./...— all packages passos.CreateTemp/os.MkdirTempin test files