Repository navigation
test: Add config loading and utility function tests - #305
Conversation
Add tests for previously-untested utility functions: - TestDeriveJWKSURL: URL derivation from token endpoint - TestReadFileContent: file reading, whitespace trimming, missing/empty files - TestLoadConfig: credential loading from files vs env var fallback - TestGetHostFromHeaders: authority vs host header precedence, edge cases go-processor coverage: 39.3% -> 50.6% Signed-off-by: Hai Huang <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
Clean, well-structured test PR. Adds 14 test cases across 4 utility functions (DeriveJWKSURL, ReadFileContent, LoadConfig, GetHostFromHeaders), improving go-processor coverage from 39.3% to 50.6%.
All tests follow Go idioms — table-driven tests, t.TempDir() for cleanup, t.Setenv for env var isolation. Good edge case coverage (nil input, empty slices, missing files). Config save/restore with mutex is nicely done.
One minor nit below, otherwise LGTM.
| t.Run("existing file with whitespace", func(t *testing.T) { | ||
| dir := t.TempDir() | ||
| path := filepath.Join(dir, "test.txt") | ||
| os.WriteFile(path, []byte(" hello world \n"), 0644) |
There was a problem hiding this comment.
nit: os.WriteFile return value is unchecked here and in a few other places (TestLoadConfig lines ~561-562). If the write silently fails, the test could pass for the wrong reason. Consider:
if err := os.WriteFile(path, []byte(" hello world \n"), 0644); err != nil {
t.Fatal(err)
}Not blocking — the subsequent assertions would likely catch it anyway.
…ty branch Resolve conflict in main_test.go: keep both utility tests (this PR) and inbound JWT validation tests (from merged PR rossoctl#304). Signed-off-by: Hai Huang <[email protected]>
Address review nit: unchecked os.WriteFile could mask test failures if the temp directory write silently fails. Signed-off-by: Hai Huang <[email protected]>
Summary
Add tests for previously-untested utility functions in go-processor:
Coverage: go-processor 39.3% -> 50.6%
When combined with inbound validation tests (#304), total coverage will reach ~60%.
Test plan