Skip to content

test: add unit tests for pkg/server/context helpers#214

Open
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052:test/server-context-coverage
Open

test: add unit tests for pkg/server/context helpers#214
mason5052 wants to merge 1 commit intovxcontrol:masterfrom
mason5052:test/server-context-coverage

Conversation

@mason5052
Copy link
Contributor

Description of the Change

Problem

backend/pkg/server/context/context.go provides typed getter functions used across the server layer but had no unit test coverage.

Solution

Add context_test.go with 15 table-driven unit tests covering all 5 exported functions: GetInt64, GetUint64, GetString, GetStringArray, and GetStringFromSession. Each function has three subtests: found, missing, and wrong-type cases.

Session tests use gin-contrib/sessions/cookie with httptest for a realistic but minimal setup.

Closes N/A

Type of Change

  • 🧪 Test update

Areas Affected

  • Core Services (Frontend UI/Backend API)

Testing and Verification

Test Configuration

os: linux
go: 1.24.1

Test Steps

  1. gofmt -w pkg/server/context/context_test.go
  2. go test ./pkg/server/context/... -count=1 -v
  3. go test ./pkg/server/context/... -count=1 -shuffle=on
  4. go vet ./pkg/server/context/...

Test Results

=== RUN   TestGetInt64
=== RUN   TestGetInt64/found
=== RUN   TestGetInt64/missing
=== RUN   TestGetInt64/wrong_type
--- PASS: TestGetInt64 (0.00s)
=== RUN   TestGetUint64
=== RUN   TestGetUint64/found
=== RUN   TestGetUint64/missing
=== RUN   TestGetUint64/wrong_type
--- PASS: TestGetUint64 (0.00s)
=== RUN   TestGetString
=== RUN   TestGetString/found
=== RUN   TestGetString/missing
=== RUN   TestGetString/wrong_type
--- PASS: TestGetString (0.00s)
=== RUN   TestGetStringArray
=== RUN   TestGetStringArray/found
=== RUN   TestGetStringArray/missing
=== RUN   TestGetStringArray/wrong_type
--- PASS: TestGetStringArray (0.00s)
=== RUN   TestGetStringFromSession
=== RUN   TestGetStringFromSession/found
=== RUN   TestGetStringFromSession/missing
=== RUN   TestGetStringFromSession/wrong_type
--- PASS: TestGetStringFromSession (0.00s)
PASS
ok  	pentagi/pkg/server/context	3.645s

Security Considerations

No security implications. Test-only change.

Performance Impact

None. Test-only change.

Documentation Updates

None required.

Deployment Notes

None. Test-only change.

Checklist

Code Quality

  • My code follows the project's coding standards
  • I have added/updated necessary documentation
  • I have added tests to cover my changes
  • All new and existing tests pass
  • I have run go fmt and go vet (for Go code)

Security

  • I have considered security implications
  • Changes maintain or improve the security model
  • Sensitive information has been properly handled

Compatibility

  • Changes are backward compatible
  • Breaking changes are clearly marked and documented
  • Dependencies are properly updated

Documentation

  • Documentation is clear and complete
  • Comments are added for non-obvious code
  • API changes are documented

Add context_test.go with 15 tests covering GetInt64, GetUint64,
GetString, GetStringArray, and GetStringFromSession. Each function
has table-driven subtests for found, missing, and wrong-type cases.
Session tests use gin-contrib/sessions/cookie with httptest.
Copilot AI review requested due to automatic review settings March 18, 2026 03:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Go test suite for the backend/pkg/server/context helper functions that extract typed values from a Gin context and session.

Changes:

  • Introduces table-driven tests for GetInt64, GetUint64, GetString, and GetStringArray.
  • Adds an integration-style test for GetStringFromSession using gin-contrib/sessions with a cookie store.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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