mirror of
https://github.com/shankar0123/certctl.git
synced 2026-06-12 12:49:00 +00:00
fix(m2-pr-d): thread ctx through Job/Notification/Audit services
Collapse CancelJobWithContext into CancelJob; eliminate 10 context.Background()
hits across the Job+Notification+Audit service cluster by threading ctx
through their handler-facing service interfaces.
Services (ctx-first):
- service/job.go: ListJobs, GetJob, CancelJob, ApproveJob, RejectJob now
accept ctx; the CancelJobWithContext wrapper is removed (handler callers
continue to invoke CancelJob, now ctx-aware).
- service/notification.go: ListNotifications, GetNotification, MarkAsRead
accept ctx.
- service/audit.go: ListAuditEvents, GetAuditEvent accept ctx.
Handlers (interface + callsites):
- handler/jobs.go, handler/notifications.go, handler/audit.go: local
service interfaces updated, r.Context() threaded at every callsite.
Tests:
- Mock services updated to match the new interfaces (ctx accepted and
ignored via '_ context.Context' first parameter; Fn closure fields
unchanged).
- job_test.go / notification_test.go callsites thread context.Background()
to match production shape.
Verification:
go build ./... ok
go vet ./... ok
go test -short ./... ok
go test -race -short ./... ok
golangci-lint run ./... 0 issues
Locked decisions from the M-2 plan:
D-1 ctx-only signatures (no dual forms)
D-4 preserve handler method names facing the router
D-5 domain types stay ctx-free
Audit complete. Commit: 1f6cf0eafa. Sections: 12. Findings: 2/7/10/4/6.
This commit is contained in:
@@ -370,7 +370,7 @@ func TestListNotifications(t *testing.T) {
|
||||
}
|
||||
|
||||
// List with pagination
|
||||
notifs, total, err := svc.ListNotifications(1, 3)
|
||||
notifs, total, err := svc.ListNotifications(context.Background(), 1, 3)
|
||||
if err != nil {
|
||||
t.Fatalf("ListNotifications failed: %v", err)
|
||||
}
|
||||
@@ -404,7 +404,7 @@ func TestMarkAsRead(t *testing.T) {
|
||||
notifRepo.AddNotification(notif)
|
||||
|
||||
// Mark as read
|
||||
err := svc.MarkAsRead(notif.ID)
|
||||
err := svc.MarkAsRead(context.Background(), notif.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("MarkAsRead failed: %v", err)
|
||||
}
|
||||
@@ -434,7 +434,7 @@ func TestGetNotification(t *testing.T) {
|
||||
notifRepo.AddNotification(notif)
|
||||
|
||||
// Get the notification
|
||||
retrieved, err := svc.GetNotification(notif.ID)
|
||||
retrieved, err := svc.GetNotification(context.Background(), notif.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("GetNotification failed: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user