[PR #214] [MERGED] test: add unit tests for pkg/server/context helpers #241

Closed
opened 2026-06-06 22:09:50 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/214
Author: @mason5052
Created: 3/17/2026
Status: Merged
Merged: 3/20/2026
Merged by: @asdek

Base: feature/next_releaseHead: test/server-context-coverage


📝 Commits (1)

  • 3e68cb2 test: add server context helper coverage

📊 Changes

1 file changed (+218 additions, -0 deletions)

View changed files

backend/pkg/server/context/context_test.go (+218 -0)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/vxcontrol/pentagi/pull/214 **Author:** [@mason5052](https://github.com/mason5052) **Created:** 3/17/2026 **Status:** ✅ Merged **Merged:** 3/20/2026 **Merged by:** [@asdek](https://github.com/asdek) **Base:** `feature/next_release` ← **Head:** `test/server-context-coverage` --- ### 📝 Commits (1) - [`3e68cb2`](https://github.com/vxcontrol/pentagi/commit/3e68cb261a715e95a2ecb0c5cb51f996b091b034) test: add server context helper coverage ### 📊 Changes **1 file changed** (+218 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `backend/pkg/server/context/context_test.go` (+218 -0) </details> ### 📄 Description ### 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 - [x] 🧪 Test update ### Areas Affected - [x] Core Services (Frontend UI/Backend API) ### Testing and Verification #### Test Configuration ```yaml 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 - [x] My code follows the project's coding standards - [x] I have added/updated necessary documentation - [x] I have added tests to cover my changes - [x] All new and existing tests pass - [x] I have run `go fmt` and `go vet` (for Go code) #### Security - [x] I have considered security implications - [x] Changes maintain or improve the security model - [x] Sensitive information has been properly handled #### Compatibility - [x] Changes are backward compatible - [x] Breaking changes are clearly marked and documented - [x] Dependencies are properly updated #### Documentation - [x] Documentation is clear and complete - [x] Comments are added for non-obvious code - [x] API changes are documented --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-06 22:09:50 -04:00
yindo closed this issue 2026-06-06 22:09:51 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#241