Skip to content

Run the conformance suite

The adapter's acceptance test is the core's conformance suite, run unchanged and once for each wire format. Run it from a checkout of messaging-nats:

go test ./...

No server needs installing: the tests start an embedded one. The suites are TestCoreConformance and TestJetStreamConformance, each with a subtest for binary, structured, masstransit and nservicebus.

go test -run 'TestCoreConformance|TestJetStreamConformance' ./...

The project's task runner has just test (with coverage), just test-race and just ci.

What each backend runs

Backend Suite Extras
Core conformance.Run conformance.WithForeign, for the unreadable-message row
JetStream conformance.RunDurable conformance.WithKillable and conformance.WithForeign

Run refuses a backend that declares SurvivesRestart, so JetStream can only run under RunDurable. See the backend contract.

The fixtures

  • Core. One embedded server for each test, from natstest.StartServer, because two rows open more than one backend and expect them to share a broker.
  • JetStream. A fixture that owns the store directory. Open builds a server over it and creates the operator's stream, CONFORMANCE, carrying a.> and b.>. Restart stops the server and starts a new one on the same directory. It also implements conformance.Binder, with a stream that does not exist, for the binding row.
  • Foreign producer. Both suites send the three kinds of unreadable message (Unclaimed, Ambiguous, Malformed) by publishing straight to the server, past the bus's writer. Every suite here reads both CloudEvents formats.
  • Killable. Kill takes the link away the way an operator does, by deleting the consumer the source is attached to. It waits for the source's pull to reach the server first, to avoid the 30-second late notice.

Run it for your own wiring

To run the suite against your own configuration of the adapter, for example with a different Format and Reads, call conformance.Run from a test and supply the backend:

conformance.Run(t, func(t *testing.T) messaging.Backend {
    return nats.Core(nats.Settings{
        Options: []client.Option{client.InProcess(serverFor(t))},
        Format:  cloudevents.Structured(),
    })
}, conformance.WithForeign(yourForeign))

serverFor is a helper that starts an embedded server; see conformance_test.go in the adapter for the one it uses.

For the contract the rows enforce, see the backend contract.