test(integration): add end-to-end integration tests #518
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/thwap-pagesd!518
Loading…
Reference in a new issue
No description provided.
Delete branch "test/integration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Add a new
internal/integrationtest package that wires the realsite.Service,webhook.Receiver, andmetrics.Registrythrough the HTTP router exactly asbuildRouterdoes incmd/thwap-pagesd/main.go, backed by in-memory repositories and fake Forgejo/Kubernetes clients.POST /api/v1/sitescreates the Forgejo repository and webhook, configures the Kubernetes ingress, persists the site, and exposes it via the status and metrics endpoints; duplicate registrations conflict.v*tag;test/*pushes publish previews;test/*deletions remove them; bad signatures are rejected with 401.v*tag, republishes, records a rollback audit event, and the status API reflects the new current deployment.Why
Phase 8 task #108 — closes the gap between the isolated handler/service unit tests by exercising the real end-to-end wiring through HTTP.
Testing
go build ./...go vet ./...go test -race -count=1 ./...— full suite incl. new integration testsgofmt -l ./cmd ./internal ./pkgcleangolangci-lint run— 0 issuesBreaking Changes
None.
Notes
RegisterSiteRequesthas no JSON tags, sopreview_enabledin the request body does not bind; the preview tests set it directly on the repository as a pre-existing limitation (out of scope here).Closes #105
Closes #106
Closes #107
Closes #108
Review Summary
Verified locally on the PR head (
a29b36b):go build,go vet,gofmt,golangci-lint runall clean; full suite incl. the new integration package passes with-race.The wiring is well done —
newAppmirrorsbuildRouterfaithfully (realsite.Service,webhook.Receiver,metrics.Registrythrough the gin router with in-memory repos and recording fakes), and the scenarios cover registration, duplicate 409, tag-push publish, preview push/delete, bad signature, and the rollback flow including audit + status reflection. These close the gap the unit tests left open.Blocking Issue
The PR's stated purpose is exercising the real end-to-end wiring through HTTP, but the preview tests don't do that for registration — because
RegisterSiteRequesthas no JSON tags, sopreview_enabledandcustom_domainin the request body are silently ignored. Empirically confirmed:POST /api/v1/siteswith{"preview_enabled":true,"custom_domain":"blog.example.org"}yields a persisted site withPreviewEnabled=false, CustomDomain="".TestWebhookPreviewPush/TestWebhookPreviewDeletetherefore bypass the API with a directa.sites.Update(...), leaving the real registration path for previews untested — and codifying the workaround instead of surfacing the defect.This also makes the README (#517, merged) inaccurate: it documents
preview_enabled/custom_domainasPOST /api/v1/sitesrequest fields.Fix (one line): add JSON tags to
RegisterSiteRequest(json:"name",json:"owner",json:"visibility",json:"custom_domain",json:"preview_enabled"), then drive the preview tests through the API (registerSitewithpreview_enabled: true) and assert the persisted site has it set. The tests should catch this class of bug, not route around it.Non-blocking Suggestions
registerSitecould take options (e.g. preview flag / custom domain) so the preview scenarios share the real path cleanly.TestRollbackScenarioreuses tag pushes with fixed SHAs — fine, but a brief comment noting the fake'stagsis the source of truth for "remaining" would help future readers.The blocking item is a one-line struct-tag addition that makes the tests genuinely end-to-end.
Addressed the blocking review item.
Blocking fix:
RegisterSiteRequestnow carries JSON tags (name,owner,visibility,custom_domain,preview_enabled) so those fields bind from thePOST /api/v1/sitesbody instead of being silently ignored. The preview tests no longer route around the real registration path:registerSitetakes options and registerspreview_enabledthrough the HTTP API, and a newTestRegistrationFlowOptionsassertscustom_domain+preview_enabledpersist. This also makes the README's documented request fields accurate.Non-blocking suggestions:
registerSitenow accepts asiteOptionsstruct (preview flag / custom domain);TestRollbackScenariocarries a comment noting the fake'stagsslice is the source of truth for remaining tags.Verification:
go build ./...,go vet ./...,go test -race -count=1 ./...,gofmt -lclean,golangci-lint run0 issues, pre-commit hooks pass. Re-requesting review.Review Summary
The blocking issue from the previous review is resolved.
RegisterSiteRequestnow carries JSON tags (name,owner,visibility,custom_domain,preview_enabled), sopreview_enabled/custom_domainbind from thePOST /api/v1/sitesbody. NewTestRegistrationFlowOptionsasserts both persist correctly.TestWebhookPreviewPush/TestWebhookPreviewDeletenow register a preview-enabled site through the API viaregisterSite(t, a, "blog", siteOptions{previewEnabled: true})instead of mutating the repository directly, exercising the real registration path.registerSitetakes optionalsiteOptions, and the rollback scenario now comments that the fake's tags slice is the source of truth for "remaining" tags.Verified locally on the PR head (
d7f1164):go build,go vet,gofmt,golangci-lint runall clean; full suite passes with-race -count=1.No blocking issues. Approving.