test

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(client *http.Client, config Config, cmd *Command) ([]byte, *http.Header, int, error)

func Execute

func Execute(t *testing.T, config Config, tests []Test)

func InitClient

func InitClient() *http.Client

InitClient is the client of every suite request: with a timeout, so that a server that stops answering fails the test instead of hanging the suite.

func Prepare

func Prepare(config Config, commands []Command)

func PrepareRequest

func PrepareRequest(config Config, cmd *Command) (*http.Request, error)

func ReadResponse

func ReadResponse(resp *http.Response) ([]byte, *http.Header, int, error)

func WaitForServer added in v0.4.0

func WaitForServer(baseURL string) error

WaitForServer polls baseURL/live until smoothdb answers. Any listener would not do: when the port is already taken by an unrelated process, Start() fails with a bind error while the squatter happily answers the probe, and the suite then runs against the wrong server with baffling failures. The /live body is the fingerprint — the Server header would not do, /live is registered outside the middleware that sets it.

Types

type Command

type Command struct {
	Description string
	Method      string
	Query       string
	Body        string
	Headers     Headers
}

type Config

type Config struct {
	BaseUrl       string
	CommonHeaders Headers
}

type Headers

type Headers http.Header

type Test

type Test struct {
	Description string
	Method      string
	Query       string
	Body        string
	Headers     Headers
	// Expected is the response body to compare against, JSON-normalized.
	// An empty Expected means "no expectation" and the body is NOT checked —
	// so it cannot express PostgREST's `shouldRespondWith ""`. Use
	// ExpectedEmpty for that.
	Expected string
	// ExpectedEmpty asserts the response body is empty. Needed because many
	// ported PostgREST tests expect exactly that (writes default to
	// `Prefer: return=minimal`), and encoding it as `Expected: ""` silently
	// degraded those tests to status-only checks.
	ExpectedEmpty bool
	// ExpectedBase64 says that Expected is the base64 encoding of a binary
	// body (an application/octet-stream download): the body is compared to
	// its decoding, byte by byte.
	ExpectedBase64  bool
	ExpectedHeaders map[string]string
	Status          int
}

We don't embed Command to simplify tests writing

Jump to

Keyboard shortcuts

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