Skip to content

test: add missing unit tests for mapper package#135

Merged
tekenstam merged 2 commits intomasterfrom
tests/improve-coverage
Mar 22, 2026
Merged

test: add missing unit tests for mapper package#135
tekenstam merged 2 commits intomasterfrom
tests/improve-coverage

Conversation

@tekenstam
Copy link
Member

Summary

Adds 15 new test functions across the pkg/mapper/ package to improve coverage of previously untested code paths.

New file: pkg/mapper/types_test.go

  • TestNew_LoggingDisabledNew() with logging disabled sets client and doesn't panic
  • TestNewRolesAuthMap / TestNewUsersAuthMap — constructors initialise all fields
  • TestRolesAuthMap_String / TestUsersAuthMap_StringString() output contains expected YAML fields
  • TestSetters_RolesAuthMap / TestSetters_UsersAuthMapSetUsername, SetGroups, AppendGroups chaining
  • TestWithRetry_SucceedsFirstAttempt — returns result on first successful call
  • TestWithRetry_ExhaustsRetries — error wraps "waiter timed out" after N retries

pkg/mapper/configmaps_test.go

  • TestCreateAuthMap_AlreadyExists — second CreateAuthMap call on same client returns an error

pkg/mapper/upsert_test.go

  • TestMapper_UpsertMultiple_EmptySlices — empty slices are a no-op (configmap unchanged)
  • TestMapper_UpsertMultiple_NilInputsnil slices handled safely, no crash

pkg/mapper/remove_test.go

  • TestMapper_RemoveRole_PartialMatchARNOnly — ARN exists but with wrong username → returns error
  • TestMapper_RemoveUser_PartialMatchARNOnly — ARN exists but with wrong username → returns error

Test plan

  • go test -v ./pkg/mapper/... — all 45 tests pass (was 30)

🤖 Generated with Claude Code

Add 15 new test functions to improve coverage:

pkg/mapper/types_test.go (new file):
- TestNew_LoggingDisabled: verify New() with logging=false
- TestNewRolesAuthMap / TestNewUsersAuthMap: constructor field init
- TestRolesAuthMap_String / TestUsersAuthMap_String: String() output format
- TestSetters_RolesAuthMap / TestSetters_UsersAuthMap: SetUsername,
  SetGroups, AppendGroups chaining
- TestWithRetry_SucceedsFirstAttempt: WithRetry returns on first success
- TestWithRetry_ExhaustsRetries: error wraps "waiter timed out" after N tries

pkg/mapper/configmaps_test.go:
- TestCreateAuthMap_AlreadyExists: second Create call returns an error

pkg/mapper/upsert_test.go:
- TestMapper_UpsertMultiple_EmptySlices: empty slices are a no-op
- TestMapper_UpsertMultiple_NilInputs: nil slices are handled safely

pkg/mapper/remove_test.go:
- TestMapper_RemoveRole_PartialMatchARNOnly: ARN+wrong username fails
- TestMapper_RemoveUser_PartialMatchARNOnly: ARN+wrong username fails

Signed-off-by: Todd Ekenstam <todd_ekenstam@intuit.com>
@tekenstam tekenstam requested a review from a team as a code owner March 22, 2026 03:50
@tekenstam tekenstam merged commit f87e68c into master Mar 22, 2026
5 checks passed
@tekenstam tekenstam deleted the tests/improve-coverage branch March 22, 2026 04:10
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.06%. Comparing base (14123df) to head (32f35c4).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #135      +/-   ##
==========================================
+ Coverage   58.70%   60.06%   +1.36%     
==========================================
  Files          12       12              
  Lines         586      586              
==========================================
+ Hits          344      352       +8     
+ Misses        219      215       -4     
+ Partials       23       19       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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