Skip to content

test: Add config loading and utility function tests - #305

Merged
huang195 merged 3 commits into
rossoctl:mainfrom
huang195:test/config-utility-functions
Apr 14, 2026
Merged

huang195 merged 3 commits into
rossoctl:mainfrom
huang195:test/config-utility-functions

Conversation

@huang195

Copy link
Copy Markdown
Member

Summary

Add tests for previously-untested utility functions in go-processor:

  • TestDeriveJWKSURL (3 cases): URL derivation from token endpoint
  • TestReadFileContent (3 cases): file reading with whitespace trimming, missing files, empty files
  • TestLoadConfig (3 cases): credential loading from files vs env var fallback, SPIRE enablement
  • TestGetHostFromHeaders (5 cases): authority vs host header precedence, missing headers, nil input

Coverage: go-processor 39.3% -> 50.6%

When combined with inbound validation tests (#304), total coverage will reach ~60%.

Test plan

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 pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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]>
@huang195
huang195 merged commit ec04140 into rossoctl:main Apr 14, 2026
15 checks passed
@huang195
huang195 deleted the test/config-utility-functions branch April 14, 2026 12:43
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.

2 participants