http-wasm technology compatibility kit (TCK)
The TCK is a test suite for checking conformance of http-wasm implementations
versus the http-wasm ABI specification.
It consists of a guest Wasm binary and a test runner which issues HTTP requests
to a given endpoint. The requests drive different test cases implemented in
the Wasm binary, and the runner verifies that the resulting response from the
endpoint matches expectations for that binary.
Running the TCK
The TCK is implemented using Go's standard testing framework, so it can be
loaded as a package for Go hosts. A TCK standalone runner is also provided
for use with Non-Go hosts, or Go hosts that would like to run the TCK outside
the standard testing framework.
The basic steps for running the TCK are
- Implement the backend handler, which is the business logic wrapped by
middleware
- Set up the middleware using the TCK guest Wasm module
- Start an HTTP server serving this middleware
- Run the tests, pointing at the URL for the HTTP server
The general flow of the HTTP request looks like the follows. Depending on the
test case, the guest Wasm may or may not pass the request to the backend.
graph LR;
A[TCK Runner] --> B[TCK Guest Wasm]
B[TCK Guest Wasm] -.-> C[Backend]
We provide an implementation of the backend handler using the Go http.Handler
interface, tck.BackendHandler.
If the Go host uses http.Handler or types that can be easily coerced to
it, it can be simplest to initialize this handler directly as the backend
being wrapped by the middleware.
It is also possible to use tck.StartBackend
to start an HTTP server using this backend handler. This is often the easiest
method for proxy servers.
Otherwise, it may be simplest to reimplement the logic in the backend handler
using the Go host's framework, following the logic in BackendHandler
.
The binary for the guest wasm module is provided as tck.GuestWASM.
With the HTTP server started and serving the middleware and backend, the tests
can be run using tck.Run.
TestTCK demonstrates a full example for the net/http middleware provided
in this repository.