test

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package test provides a conformance harness for chat-platform providers.

The compiler checks a provider's method set. It cannot check the rules a caller actually relies on: that asking for a read-only provider yields one with nothing to post through, that Close is safe on a provider that never connected, that Messages returns a channel a caller can range over, or that the capabilities a provider claims are the ones it has. A provider can satisfy every interface in the contract and still be wrong in each of those ways.

Run it from the provider's own test suite:

func TestConformance(t *testing.T) {
    chatplatformtest.RunProviderConformance(t, chatplatformtest.ConformanceConfig{
        NewProvider:    func(c chatplatform.Config) (*chatplatform.Provider, error) { return mydiscord.New(c) },
        Capabilities:   chatplatformtest.Capabilities{Moderator: true, Interactive: true},
        Space:          "123",
        AllowedChannel: "456",
    })
}

Every check runs without a network. Behaviour that needs a live platform — that a thread is really created, that the allowlist really filters an inbound feed — belongs in the provider's own integration tests, gated behind an environment variable. The harness covers the contract a consumer depends on before a single message arrives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunProviderConformance

func RunProviderConformance(t *testing.T, cfg ConformanceConfig)

RunProviderConformance runs every check and reports what it finds.

Types

type Capabilities

type Capabilities struct {
	Moderator       bool
	MemberInspector bool
	Interactive     bool
	Commands        bool
}

Capabilities declares what the provider under test supports, so the harness can tell "correctly does not offer this" apart from "should and does not".

Declare honestly. Claiming a capability the provider lacks makes the harness look for something impossible; omitting one it has means nobody discovers it.

type ConformanceConfig

type ConformanceConfig struct {
	// NewProvider builds a provider from the given config. Called once per
	// check, so each gets an independent instance.
	NewProvider func(chatplatform.Config) (*chatplatform.Provider, error)

	// Capabilities the provider claims.
	Capabilities Capabilities

	// Space is the guild, workspace or network the provider serves.
	Space chatplatform.ID

	// AllowedChannel is a channel the provider should accept in its allowlist.
	AllowedChannel chatplatform.ID
}

ConformanceConfig configures a run.

Jump to

Keyboard shortcuts

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