Skip to content

test(handler): add unit tests for groups.go - #1602

Draft
damnnmanyaa wants to merge 1 commit into
flatcar:mainfrom
damnnmanyaa:test/handler-coverage-groups
Draft

test(handler): add unit tests for groups.go#1602
damnnmanyaa wants to merge 1 commit into
flatcar:mainfrom
damnnmanyaa:test/handler-coverage-groups

Conversation

@damnnmanyaa

@damnnmanyaa damnnmanyaa commented Aug 20, 2026

Copy link
Copy Markdown

Addresses #1581, scoped to groups.go

What's covered

Unit tests for all 11 exported handler functions in backend/pkg/handler/groups.go, using httptest + echo.Context against a real seeded Postgres database via api.NewForTest matching the existing pattern already established in this codebase (backend/pkg/api/metrics_test.go).

Each handler is covered for:

  • A successful request (correct status code + response shape)
  • A not-found or app-not-found case where applicable
  • A malformed/validation-failure case (invalid ID, invalid duration, malformed JSON body)

Note for reviewers: nonexistent group IDs on aggregate endpoints

The group aggregate endpoints currently return 200 with empty data when given a syntactically valid but nonexistent group ID :-

  • GET .../version_timeline
  • GET .../status_timeline
  • GET .../version_breakdown

These handlers query aggregate data tables directly rather than resolving the group first (unlike GetGroup, UpdateGroup, and DeleteGroup, which query the groups table via dbreads.Queries.GetGroup and 404 on sql.ErrNoRows). As a result, a nonexistent group with no matching instance or status-history rows is currently indistinguishable from an
existing group that simply has no data yet.

This is out of scope for this test-coverage PR. The tests reflect actual current behavior rather than assuming what it should be. Happy to open a follow-up issue if maintainers think this is worth addressing, or to leave it as intentional empty-aggregate semantics if that's by design.

Next steps

Plan is to extend this same pattern to the other handler files (channels.go, packages.go, etc.) in follow-up PRs once this one is reviewed.

Signed-off-by: Manya <174072426+damnnmanyaa@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 20, 2026 22:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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