Skip to content

Comments

test: enhance unit test coverage across internal packages#28

Draft
mskutin wants to merge 2 commits intomainfrom
test/unit-test-coverage-improvements
Draft

test: enhance unit test coverage across internal packages#28
mskutin wants to merge 2 commits intomainfrom
test/unit-test-coverage-improvements

Conversation

@mskutin
Copy link
Owner

@mskutin mskutin commented Jan 24, 2026

Summary

Improve test coverage for three packages with low coverage: internal/budgets, internal/cmd, and internal/policy.

Test Coverage Improvements

Package Before After Improvement
internal/budgets 51.5% 70.7% +19.2%
internal/cmd 14.7% 28.7% +14.0%
internal/policy 44.0% 76.0% +32.0%

Changes

internal/budgets/client_test.go (+40 test cases, ~736 lines)

  • Tests for NewClientWithAssumeRole() - Role assumption constructor
  • Tests for getClientForAccount() - Core role assumption logic
  • Tests for parseBudgetConfig() - AWS Budget to internal format conversion
  • Tests for GetAllAccountsBudgetsWithProgress() - Progress callback functionality
  • Role assumption scenarios (valid ARN, invalid account, non-existent role)
  • Budget parsing with various configurations (valid, missing fields, invalid limits)
  • Concurrent access patterns
  • Error classification for AWS API errors

internal/cmd/root_test.go (+73 test cases, ~904 lines)

  • Tests for printBanner() - Banner printing with version info
  • Tests for loadAWSConfig() - AWS SDK configuration loading
  • Tests for filterAccounts() - Account filtering by ID
  • Tests for filterAccountsByOU() - OU filtering
  • Tests for discoverAccounts() - AWS Organizations account discovery
  • Account filtering scenarios
  • Flag availability and default values validation
  • Context cancellation handling

internal/policy/resolver_test.go (+72 test cases, ~1,644 lines)

  • Tests for LoadAccountMetadata() - AWS API calls for OU and tag info
  • Tests for ValidateOUs() - OU validation against AWS Organizations
  • Successful OU and tag loading scenarios
  • Permission error handling (graceful degradation)
  • Policy resolution priority rules (account > tag > OU > default)
  • Complete override scenarios
  • Zero value override handling

Testing

go test ./internal/budgets -v -cover   # 70.7% coverage
go test ./internal/cmd -v -cover       # 28.7% coverage
go test ./internal/policy -v -cover    # 76.0% coverage
go test ./... -cover                    # all packages

Checklist

- Tests follow table-driven test pattern where applicable
- Tests cover both success and error paths
- Tests include edge cases (empty results, nil pointers, invalid formats)
- All tests pass
- Code formatted with gofmt

mskutin and others added 2 commits January 24, 2026 22:45
- Add comprehensive tests for budgets client (70.7% coverage, up from 51.5%)
- Add tests for policy resolver (76.0% coverage, up from 44.0%)
- Add tests for cmd package (28.7% coverage, up from 14.7%)

New test coverage includes:
- Role assumption and budget parsing scenarios
- Policy resolution with priority rules (account > tag > OU > default)
- Account filtering by ID and Organizational Unit
- AWS configuration loading
- Banner printing and CLI flag validation
- Error handling for AWS API calls
- Concurrent access patterns

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

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