Skip to content

Replace custom test dispatcher with Gadget testing utilities #49

@xortim

Description

@xortim

Problem

integration/handler.go contains ~90 lines that replicate Gadget's internal event dispatch logic so handlers can be tested without a database or HTTP server:

// integration/handler.go
func TestHandler(r router.Router, routes []router.ChannelMessageRoute, ...) (int, error) {
    // verify signature, parse event, match route, execute handler synchronously
}

This is fragile — if Gadget's dispatch logic changes, this test helper silently diverges. It also has to execute handlers synchronously (Gadget uses async goroutines), adding another behavioral difference.

What changes

Replace integration/handler.go with Gadget's official test utilities:

// Before: custom 90-line test dispatcher
result, err := integration.TestHandler(r, routes, body, header)

// After: Gadget-provided test dispatcher
dispatcher := gadgettest.NewDispatcher(gadgettest.WithRoutes(routes...))
err := dispatcher.DispatchMessage(event)

Blocked by

Files affected

  • integration/handler.go — remove entirely
  • gadgets/hallmonitor/spam_feed_test.go — update to use Gadget test utilities (if integration-level tests use the dispatcher)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions