conformance

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package conformance holds the WebSub and PubSubHubbub 0.4 conformance cases for this package, written so they can be replayed against a websub handler mounted behind any router.

The core module runs them directly. Each adapter module runs the same cases through its own wrapper, which is where a bug in the wrapping shows up: a framework that drops a header, rewrites a path, or consumes the request body breaks a case here rather than in production. If you are writing an adapter of your own, run them the same way:

func TestConformance(t *testing.T) {
	conformance.Run(t, conformance.Config{
		Wrap: func(h http.Handler) http.Handler { return myAdapter(h) },
	})
}

This package is a test helper. It carries no compatibility promise, and the set of cases grows whenever a conformance gap is found.

Index

Constants

View Source
const TestLease = 90 * time.Minute

TestLease is the lease fakeHub grants.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, cfg Config)

Run executes every conformance case for all three roles.

func RunHub

func RunHub(t *testing.T, cfg Config)

RunHub executes the hub conformance cases: subscription handling, lease policy, verification, and content distribution.

func RunPassthrough

func RunPassthrough(t *testing.T, cfg Config)

RunPassthrough checks that a router preserves the request and response details this protocol depends on.

The full suite in Run already covers these indirectly, but a failure there is hard to read. These cases fail with the exact byte, header, or status that went missing, which is what you want when a framework's request translation is the suspect.

func RunPublisher

func RunPublisher(t *testing.T, cfg Config)

RunPublisher executes the publisher conformance cases: discovery advertisement and both publishing methods.

func RunSubscriber

func RunSubscriber(t *testing.T, cfg Config)

RunSubscriber executes the subscriber conformance cases: discovery, subscription requests, verification of intent, denial, and authenticated content distribution.

Types

type Config

type Config struct {
	// Wrap mounts a websub handler behind the router under test and returns
	// something serving the same requests. Nil means test the handler
	// directly, which is what the core module does.
	//
	// The handler must be mounted so that every path below the root reaches
	// it, since a subscriber's callbacks live under a prefix.
	Wrap func(http.Handler) http.Handler

	// Serve mounts a websub handler on the router under test, starts it, and
	// returns the base URL it is reachable at. It must register its own
	// cleanup. When nil, the suite serves Wrap(h) on an httptest server.
	Serve func(t *testing.T, h http.Handler) string

	// Modes restricts the run to particular spec modes. Empty means every
	// mode a case declares support for.
	Modes []websub.Mode
}

Config describes the implementation under test.

Set at most one of Wrap and Serve. Wrap suits any router that is itself an http.Handler, which is most of them. Serve exists for frameworks built on something other than net/http, where running the framework's own server is the only faithful test.

type Delivery

type Delivery struct {
	ContentType string
	Signature   string
	Links       []string
	Body        string
}

Delivery is one content distribution request as a subscriber saw it.

type Notification

type Notification struct {
	Topic       string
	ContentType string
	Body        string
}

Notification is one content distribution request as a subscriber saw it.

type PublishRequest

type PublishRequest struct {
	Form        url.Values
	ContentType string
	Body        string
	Links       []string
}

PublishRequest is one publish notification as a hub saw it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL