A Go websocket client for unit testing websocket handlers without requiring a live server.
wstest is a Go library that provides a websocket client for unit testing websocket server handlers. It solves the problem of testing websocket upgrade logic without requiring a live HTTP server, making tests faster and more isolated by running the handler directly in a goroutine.
Go developers who are building websocket servers using the Gorilla websocket package and need to write unit tests for their websocket handlers.
Developers choose wstest because it eliminates the need for a live server in websocket tests, reducing test complexity and execution time while maintaining compatibility with the standard Gorilla websocket implementation.
go websocket client for unit testing of a websocket handler
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Eliminates the need for httptest.NewServer by running websocket handlers directly in goroutines without listening on ports, making tests faster and more isolated, as highlighted in the README's comparison example.
Specifically designed for the popular Gorilla websocket package, returning a standard websocket.Dialer that integrates with existing client code, ensuring compatibility without modifications.
Replaces httptest.Server setup with a single NewDialer function call, reducing boilerplate and making test suites cleaner, as demonstrated in the README's diff example.
Allows focused testing of websocket upgrade logic and handler functions without server infrastructure, improving isolation and debugging efficiency for unit tests.
Limited to the Gorilla websocket implementation; projects using other libraries cannot leverage wstest, forcing reliance on httptest.Server or custom solutions.
Bypasses the network layer, so it doesn't test edge cases like network latency, connection drops, or server behavior under load, which are crucial for production-ready applications.
Running handlers in goroutines without a server might introduce subtle race conditions or concurrency issues, especially for stateful handlers, requiring careful test design.