testing

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package testing is the assertion vocabulary a test writes against.

It holds the bare assertions (AssertTrue, AssertSame, AssertCount and the rest), the things worth asserting about (TestResponse for what a handler answered, AssertableJSONString for a decoded payload, TestView for a rendered view, TestComponent for a rendered component, PendingCommand for a console command), and the two pieces around a run (ParallelTesting for the per-process callbacks, LoggedExceptionCollection for what the handler recorded).

Everything reports through T

No assertion here takes *testing.T. They take T, which is the part of it they use, so an assertion can be tested by handing it a recorder instead of a real test -- which is how this package's own tests check that a failing assertion fails.

Every assertion calls Helper before it reports, so a failure is blamed on the line in the test rather than on the line inside the assertion.

Failure messages carry the context

An assertion on a TestResponse appends the status, the headers and the body to its message. The answer to "why is this a 500" is in the response, and finding it out otherwise means running the test again with a print.

Subpackages

hesape/testing/constraints holds the reusable matchers, so a comparison used by more than one assertion is written once. hesape/testing/fluent holds the chained assertion language over a decoded JSON payload.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertArrayHasKey

func AssertArrayHasKey(t T, key string, array any, message string)

AssertArrayHasKey fails unless the map has the key. It looks at one level, not at a dot path.

func AssertArraySubset

func AssertArraySubset(t T, subset, array any, checkForIdentity bool, msg string) error

AssertArraySubset fails unless the value carries everything the subset names. It may carry more.

checkForIdentity picks the comparison: identity when true, the relaxed one when false. The error result reports an argument that is neither a list nor a map, and no assertion is made in that case.

func AssertContains

func AssertContains(t T, needle any, haystack []string, message string)

AssertContains fails unless one element of the haystack compares loosely equal to the needle.

func AssertCount

func AssertCount(t T, expected int, actual any, message string)

AssertCount fails unless the value is countable and its length is the one expected.

func AssertEmpty

func AssertEmpty(t T, actual any, message string)

AssertEmpty fails unless the value is empty: nil, false, zero, the empty string, "0", and the empty list or map.

func AssertEquals

func AssertEquals(t T, expected, actual any, message string)

AssertEquals fails unless the two values compare loosely equal, which holds a string and the number it spells to be equal.

func AssertEqualsCanonicalizing

func AssertEqualsCanonicalizing(t T, expected, actual any, message string)

AssertEqualsCanonicalizing fails unless the two values are equal once both sides are sorted, so the order of a list does not count.

func AssertFalse

func AssertFalse(t T, condition bool, message string)

AssertFalse fails unless the condition is false.

func AssertGreaterThanOrEqual

func AssertGreaterThanOrEqual(t T, expected, actual int, message string)

AssertGreaterThanOrEqual fails unless actual is at least expected.

func AssertIsArray

func AssertIsArray(t T, actual any, message string)

AssertIsArray fails unless the value is a list, an array or a map.

func AssertLessThanOrEqual

func AssertLessThanOrEqual(t T, expected, actual int, message string)

AssertLessThanOrEqual fails unless actual is at most expected.

func AssertNotContains

func AssertNotContains(t T, needle any, haystack []string, message string)

AssertNotContains fails when an element of the haystack compares loosely equal to the needle.

func AssertNotEmpty

func AssertNotEmpty(t T, actual any, message string)

AssertNotEmpty fails when the value is empty.

func AssertNotEquals

func AssertNotEquals(t T, expected, actual any, message string)

AssertNotEquals fails when the two values compare loosely equal.

func AssertNotNull

func AssertNotNull(t T, actual any, message string)

AssertNotNull fails when the value is nil.

func AssertNotSame

func AssertNotSame(t T, expected, actual any, message string)

AssertNotSame fails when the two values are identical.

func AssertNotTrue

func AssertNotTrue(t T, condition bool, message string)

AssertNotTrue fails unless the value is anything other than true.

func AssertNull

func AssertNull(t T, actual any, message string)

AssertNull fails unless the value is nil.

func AssertSame

func AssertSame(t T, expected, actual any, message string)

AssertSame fails unless the two values are identical. It is identity, not equality.

func AssertStringContainsString

func AssertStringContainsString(t T, needle, haystack, message string)

AssertStringContainsString fails unless the haystack contains the needle.

func AssertStringNotContainsString

func AssertStringNotContainsString(t T, needle, haystack, message string)

AssertStringNotContainsString fails when the haystack contains the needle.

func AssertThat

func AssertThat(t T, value any, c constraints.Constraint, message string)

AssertThat evaluates a constraint and reports what it says when it does not hold.

func AssertTrue

func AssertTrue(t T, condition bool, message string)

AssertTrue fails unless the condition is true.

func Fail

func Fail(t T, message string)

Fail reports a failure with the given message and stops the test.

Types

type AssertableJSONString

type AssertableJSONString struct {

	// JSONValue is what was handed in, before it was decoded. It is named for
	// what it holds, because [AssertableJSONString.JSON] is the method that
	// reads the decoded half.
	JSONValue any
	// contains filtered or unexported fields
}

AssertableJSONString is a decoded JSON payload with the assertions worth making about it.

func NewAssertableJSONString

func NewAssertableJSONString(t T, jsonable any) *AssertableJSONString

NewAssertableJSONString wraps a payload for assertion.

A string or a byte slice is decoded; anything else is taken as the already decoded value.

Input that is not JSON leaves AssertableJSONString.Decoded nil rather than failing here, which is the state TestResponse.DecodeResponseJSON checks for so it can report the exception the route logged instead.

func (*AssertableJSONString) AssertCount

func (a *AssertableJSONString) AssertCount(count int, key ...string) *AssertableJSONString

AssertCount asserts the payload, or what is at the given dot path, has the expected number of entries.

func (*AssertableJSONString) AssertExact

func (a *AssertableJSONString) AssertExact(data any) *AssertableJSONString

AssertExact asserts the payload is the given value and nothing else.

encoding/json already writes object keys in sorted order, so encoding both sides is the same normalisation with one step instead of three.

func (*AssertableJSONString) AssertFragment

func (a *AssertableJSONString) AssertFragment(data any) *AssertableJSONString

AssertFragment asserts every pair in the given value appears somewhere in the payload.

The search is over the encoded payload, which is why a fragment matches at any depth -- and why it can match a pair nested somewhere the test did not mean.

func (*AssertableJSONString) AssertMissing

func (a *AssertableJSONString) AssertMissing(data any, exact bool) *AssertableJSONString

AssertMissing asserts no pair in the given value appears in the payload. Passing exact as true is AssertableJSONString.AssertMissingExact instead.

func (*AssertableJSONString) AssertMissingExact

func (a *AssertableJSONString) AssertMissingExact(data any) *AssertableJSONString

AssertMissingExact asserts the payload does not carry the whole of the given value.

One pair missing is enough to pass, which is what makes it the exact form: AssertableJSONString.AssertMissing fails when any pair is present, this one only when they all are.

func (*AssertableJSONString) AssertMissingPath

func (a *AssertableJSONString) AssertMissingPath(path string) *AssertableJSONString

AssertMissingPath asserts nothing is at the dot path.

func (*AssertableJSONString) AssertPath

func (a *AssertableJSONString) AssertPath(path string, expect any) *AssertableJSONString

AssertPath asserts the value at the path is the expected one, of the expected type.

An expectation of func(any) bool is a truth test over what is at the path, which is how a test says "an id, whatever it turned out to be".

func (*AssertableJSONString) AssertPathCanonicalizing

func (a *AssertableJSONString) AssertPathCanonicalizing(path string, expect any) *AssertableJSONString

AssertPathCanonicalizing asserts the value at the path is the expected one once both sides are sorted, so order does not count.

func (*AssertableJSONString) AssertSimilar

func (a *AssertableJSONString) AssertSimilar(data any) *AssertableJSONString

AssertSimilar asserts the payload is the given value, in any order.

func (*AssertableJSONString) AssertStructure

func (a *AssertableJSONString) AssertStructure(structure, responseData any, exact bool) *AssertableJSONString

AssertStructure asserts the payload has these keys, nested this way. Passing exact as true also asserts there are no other keys at each level.

How a structure is written

The two halves are written separately:

  • []any or []string names keys only: every element is a key the payload has to carry, and nothing is said about what is under it.
  • map[string]any names keys and their contents: every key has to be carried, and its value is the structure of what is under it. A nil value says nothing about what is under it, which is how the keys-only form is written inside a map.

The key "*" is the wildcard, and it applies the structure under it to every element of the payload at that level.

Pass nil for responseData from a test: it is how the recursion hands a nested level back to itself.

func (*AssertableJSONString) AssertSubset

func (a *AssertableJSONString) AssertSubset(data any, strict bool) *AssertableJSONString

AssertSubset asserts the payload carries at least the given value. Passing strict as true compares by identity rather than loosely.

func (*AssertableJSONString) Count

func (a *AssertableJSONString) Count() int

Count returns the number of entries in the payload, or 0 when it is not countable.

func (*AssertableJSONString) Decoded

func (a *AssertableJSONString) Decoded() any

Decoded is the decoded payload.

func (*AssertableJSONString) JSON

func (a *AssertableJSONString) JSON(key ...string) any

JSON reads a value by dotted path, or the whole payload when no path is given.

type LoggedExceptionCollection

type LoggedExceptionCollection []error

LoggedExceptionCollection is every error the application logged while a request was being handled, in the order they were logged.

It is a slice because the type exists to be named in a signature, not to add behaviour.

func (LoggedExceptionCollection) Count

func (c LoggedExceptionCollection) Count() int

Count returns how many errors were logged.

func (LoggedExceptionCollection) First

func (c LoggedExceptionCollection) First() error

First returns the first error logged, or nil when nothing was.

func (LoggedExceptionCollection) IsEmpty

func (c LoggedExceptionCollection) IsEmpty() bool

IsEmpty reports whether nothing was logged.

func (LoggedExceptionCollection) Last

Last returns the last error logged, or nil when nothing was.

It is the one a failure message uses: when a handler catches an error, logs it and answers 500, the last logged error is the cause, and printing it is the difference between "expected 200, got 500" and a sentence naming the bug.

func (LoggedExceptionCollection) Push

Push appends errors and returns the extended collection, the way append does.

type ParallelTesting

type ParallelTesting struct {
	// contains filtered or unexported fields
}

ParallelTesting holds the callbacks an application registers to be run at the boundaries of a parallel test run -- when a worker process starts and ends, when a test case is set up and torn down, and when a per-worker test database is created.

It is a plain value: build one with NewParallelTesting, keep it where the test bootstrap can reach it, and pass it.

Every method is safe for concurrent use. Callbacks are copied out from under the lock and then called with the lock released, so that a callback may register another one without deadlocking.

The callbacks fire only while running in parallel, which here means only that a token resolves -- see ParallelTesting.Token.

func NewParallelTesting

func NewParallelTesting() *ParallelTesting

NewParallelTesting returns a ParallelTesting with no callbacks and no resolvers installed.

func (*ParallelTesting) CallSetUpProcessCallbacks

func (p *ParallelTesting) CallSetUpProcessCallbacks()

CallSetUpProcessCallbacks runs the registered process set-up callbacks, in the order they were registered, if a token resolves.

func (*ParallelTesting) CallSetUpTestCaseCallbacks

func (p *ParallelTesting) CallSetUpTestCaseCallbacks(testCase T)

CallSetUpTestCaseCallbacks runs the registered test case set-up callbacks, in the order they were registered, if a token resolves.

func (*ParallelTesting) CallSetUpTestDatabaseCallbacks

func (p *ParallelTesting) CallSetUpTestDatabaseCallbacks(database string)

CallSetUpTestDatabaseCallbacks runs the registered test database set-up callbacks, in the order they were registered, if a token resolves.

func (*ParallelTesting) CallTearDownProcessCallbacks

func (p *ParallelTesting) CallTearDownProcessCallbacks()

CallTearDownProcessCallbacks runs the registered process tear-down callbacks, in the order they were registered, if a token resolves.

func (*ParallelTesting) CallTearDownTestCaseCallbacks

func (p *ParallelTesting) CallTearDownTestCaseCallbacks(testCase T)

CallTearDownTestCaseCallbacks runs the registered test case tear-down callbacks, in the order they were registered, if a token resolves.

func (*ParallelTesting) Option

func (p *ParallelTesting) Option(option string) (any, bool)

Option reads a parallel testing option, reporting whether it was set.

With no resolver installed the value comes from the environment, under the option's name upper-cased and prefixed -- "recreate databases" is read from PARALLEL_TESTING_RECREATE_DATABASES.

func (*ParallelTesting) ResolveOptionsUsing

func (p *ParallelTesting) ResolveOptionsUsing(resolver func(option string) (any, bool))

ResolveOptionsUsing installs the callback ParallelTesting.Option asks for a value.

func (*ParallelTesting) ResolveTokenUsing

func (p *ParallelTesting) ResolveTokenUsing(resolver func() (string, bool))

ResolveTokenUsing installs the callback ParallelTesting.Token asks for the unique process token.

func (*ParallelTesting) SetUpProcess

func (p *ParallelTesting) SetUpProcess(callback func(token string))

SetUpProcess registers a callback to run once, at the start of each worker process.

func (*ParallelTesting) SetUpTestCase

func (p *ParallelTesting) SetUpTestCase(callback func(testCase T, token string))

SetUpTestCase registers a callback to run before each test case.

func (*ParallelTesting) SetUpTestDatabase

func (p *ParallelTesting) SetUpTestDatabase(callback func(database string, token string))

SetUpTestDatabase registers a callback to run once per worker, after its own copy of the test database has been created. The callback receives the database name and the token.

func (*ParallelTesting) TearDownProcess

func (p *ParallelTesting) TearDownProcess(callback func(token string))

TearDownProcess registers a callback to run once, as each worker process ends.

func (*ParallelTesting) TearDownTestCase

func (p *ParallelTesting) TearDownTestCase(callback func(testCase T, token string))

TearDownTestCase registers a callback to run after each test case.

func (*ParallelTesting) Token

func (p *ParallelTesting) Token() (string, bool)

Token returns the token that tells one worker of a parallel run from another, and which names its database, its cache prefix and its temporary files. It reports whether one resolved at all.

With no resolver installed it comes from the TEST_TOKEN environment variable, and an empty TEST_TOKEN counts as no token.

type PendingCommand

type PendingCommand struct {
	// Test is the test being run.
	Test T
	// contains filtered or unexported fields
}

PendingCommand is a console command that has been described and not yet run.

The kernel it runs on is an explicit field, so what the command runs on is visible at the call site.

The expectations live here rather than on the test. Nothing else reads them, and PendingCommand.Run clears them once it has checked them.

func NewPendingCommand

func NewPendingCommand(t T, kernel PendingCommandKernel, command string, parameters []string) *PendingCommand

NewPendingCommand describes a command to run on the given kernel. Nothing runs until PendingCommand.Run.

func (*PendingCommand) AssertExitCode

func (c *PendingCommand) AssertExitCode(exitCode int) *PendingCommand

AssertExitCode records that the command must exit with this status. The assertion is made when the command runs, which is where the status exists.

func (*PendingCommand) AssertFailed

func (c *PendingCommand) AssertFailed() *PendingCommand

AssertFailed records that the command must exit with anything other than zero.

func (*PendingCommand) AssertNotExitCode

func (c *PendingCommand) AssertNotExitCode(exitCode int) *PendingCommand

AssertNotExitCode records that the command must exit with any status other than this one.

func (*PendingCommand) AssertOk

func (c *PendingCommand) AssertOk() *PendingCommand

AssertOk is PendingCommand.AssertSuccessful under a shorter name.

func (*PendingCommand) AssertSuccessful

func (c *PendingCommand) AssertSuccessful() *PendingCommand

AssertSuccessful records that the command must exit zero.

func (*PendingCommand) DoesntExpectOutput

func (c *PendingCommand) DoesntExpectOutput(output ...string) *PendingCommand

DoesntExpectOutput records that none of the lines given may be printed.

Called with no argument it records that the command must print nothing at all.

func (*PendingCommand) DoesntExpectOutputToContain

func (c *PendingCommand) DoesntExpectOutputToContain(s string) *PendingCommand

DoesntExpectOutputToContain records that the string must appear nowhere in what the command printed.

func (*PendingCommand) Execute

func (c *PendingCommand) Execute(ctx context.Context) int

Execute is PendingCommand.Run under another name.

func (*PendingCommand) ExpectsChoice

func (c *PendingCommand) ExpectsChoice(question string, answer any, answers []string, strict bool) *PendingCommand

ExpectsChoice records that the question must be asked, that it must offer these options, and that this is the one picked.

strict asks for the options in this exact order; otherwise any order will do. Recording the same question twice replaces its options.

func (*PendingCommand) ExpectsConfirmation

func (c *PendingCommand) ExpectsConfirmation(question, answer string) *PendingCommand

ExpectsConfirmation records a yes/no question and the answer to it. Any answer other than "yes", in any case, is taken as no.

func (*PendingCommand) ExpectsOutput

func (c *PendingCommand) ExpectsOutput(output ...string) *PendingCommand

ExpectsOutput records that each line given must be printed, in this order.

Called with no argument it records only that the command must print something. The variadic is what tells the omitted argument from the empty line.

func (*PendingCommand) ExpectsOutputToContain

func (c *PendingCommand) ExpectsOutputToContain(s string) *PendingCommand

ExpectsOutputToContain records that the string must be somewhere in what the command printed, on any line.

func (*PendingCommand) ExpectsQuestion

func (c *PendingCommand) ExpectsQuestion(question string, answer any) *PendingCommand

ExpectsQuestion records that the question must be asked when the command runs, and that this is the answer it gets.

A bool is typed as yes or no, an int as itself, a slice as a comma separated list -- the three forms console.IO.Confirm and console.IO.Choice read.

func (*PendingCommand) ExpectsSearch

func (c *PendingCommand) ExpectsSearch(question string, answer any, search string, answers []string) *PendingCommand

ExpectsSearch records a search: the question is asked twice, once for the search string and once for the choice it narrowed down to.

func (*PendingCommand) ExpectsTable

func (c *PendingCommand) ExpectsTable(headers []string, rows [][]string) *PendingCommand

ExpectsTable records that the command must print this table.

The table is rendered here by the same renderer the command uses, and every line of it becomes an expected output line. A second renderer written for tests would be a second way to draw a table.

func (*PendingCommand) Run

func (c *PendingCommand) Run(ctx context.Context) int

Run executes the command, asserts the status and then every expectation that was recorded, clears them, and returns the status.

A question the test did not script reaches the end of the input, and the console reports that it ran out of answers -- which arrives here as a failed status and as output, both of which are asserted.

type PendingCommandKernel

type PendingCommandKernel interface {
	Call(ctx context.Context, command string, parameters []string, in io.Reader, out io.Writer) error
}

PendingCommandKernel runs one console command for a PendingCommand.

It takes a context, because running a command is I/O, and it takes the input as well as the output: a console.IO reads its answers from a reader and writes its prompts to a writer, so the seam is the two streams.

type T

type T interface {
	Helper()
	Fatalf(format string, args ...any)
	Logf(format string, args ...any)
}

T is what an assertion in this package needs from the test it runs inside. The standard library's *testing.T satisfies it.

Continuing after a failed assertion would let the assertions that follow read a response the first one already proved wrong. Logf is here for the dump methods rather than for the assertions: dump() and dumpHeaders() have to write somewhere, and a test's own log is where output belongs -- go test shows it beside the test that produced it and hides it when the test passes.

type TestComponent

type TestComponent struct {

	// Component is the component before it was drawn.
	Component view.Component
	// contains filtered or unexported fields
}

TestComponent is a component that has been drawn, with the assertions worth making about the HTML it produced.

It is TestView's smaller sibling, and the difference is what each one holds on to. TestView keeps the view, so it can assert about the data that was bound; TestComponent keeps the component itself, on an exported field, so a test that wants something off it reads it by name.

Every assertion returns the component.

rendered.AssertSee("Save").AssertDontSee("Delete")

func NewTestComponent

func NewTestComponent(t T, component view.Component, v *view.View) (*TestComponent, error)

NewTestComponent renders the view and wraps it, keeping the component alongside it.

It returns an error for a nil view and for a view that would not render, so a template failure is reported where it happened rather than as an empty page three assertions later.

func (*TestComponent) AssertDontSee

func (c *TestComponent) AssertDontSee(value string, escape ...bool) *TestComponent

AssertDontSee asserts the text is not in the rendered component.

func (*TestComponent) AssertDontSeeText

func (c *TestComponent) AssertDontSeeText(value string, escape ...bool) *TestComponent

AssertDontSeeText asserts the text is not in the rendered component once the tags are taken off.

func (*TestComponent) AssertSee

func (c *TestComponent) AssertSee(value string, escape ...bool) *TestComponent

AssertSee asserts the text is in the rendered component. The text is HTML-escaped first unless escape is given as false.

func (*TestComponent) AssertSeeInOrder

func (c *TestComponent) AssertSeeInOrder(values []string, escape ...bool) *TestComponent

AssertSeeInOrder asserts the strings are in the rendered component, each one after the last.

func (*TestComponent) AssertSeeText

func (c *TestComponent) AssertSeeText(value string, escape ...bool) *TestComponent

AssertSeeText asserts the text is in the rendered component once the tags are taken off.

func (*TestComponent) AssertSeeTextInOrder

func (c *TestComponent) AssertSeeTextInOrder(values []string, escape ...bool) *TestComponent

AssertSeeTextInOrder asserts the strings are in the rendered component once the tags are taken off, each one after the last.

func (*TestComponent) ToString

func (c *TestComponent) ToString() string

ToString returns the rendered component.

type TestResponse

type TestResponse struct {

	// BaseRequest is the request that produced this response.
	BaseRequest *http.Request

	// BaseResponse is the response itself.
	BaseResponse *http.Response

	// Exceptions is what the request logged on its way through. The last one is
	// appended to a failure message by messageWithContext.
	Exceptions LoggedExceptionCollection

	// Original is what the handler returned before it became bytes -- a
	// *view.View, for the view assertions. It is recorded rather than inferred,
	// because the bytes no longer say what produced them.
	Original any

	// URL is the generator the location assertions resolve against.
	//
	// AssertLocation, AssertRedirectBack, AssertRedirectToRoute and
	// AssertRedirectToSignedRoute need it, and say so when it is missing rather
	// than guessing. Nothing else here touches it.
	URL *routing.UrlGenerator

	// Encrypter is what [TestResponse.AssertCookie] decrypts with. A test
	// asserting about an unencrypted cookie does not need it: that is
	// [TestResponse.AssertPlainCookie].
	Encrypter *encryption.Encrypter

	// Flash is what reads the validation errors and the old input back off the
	// response.
	//
	// They travel in a signed one-shot cookie rather than in the session -- see
	// session.Flash, and the reason it gives: the three forms that need them most
	// are submitted by somebody who has no session at all.
	//
	// A test that asserts about errors or old input sets it. AssertSessionHas
	// and AssertSessionMissing do not need it: those read the session store,
	// which is a general key/value store in both languages.
	Flash *session.Flash

	// Streamed records that the handler streamed the response.
	//
	// Every response arrives as an *http.Response, so what the handler did is
	// recorded rather than inferred -- the same reason Original is a field. A
	// response that arrived chunked is streamed whether or not anybody set this,
	// which AssertStreamed also reads.
	Streamed bool
	// contains filtered or unexported fields
}

TestResponse is what came back from a request, with the assertions worth making about it.

Every assertion returns the response.

response.AssertOK().AssertSee("Invoices").AssertDontSee("Draft")

func FromBaseResponse

func FromBaseResponse(t T, response *http.Response, request *http.Request) *TestResponse

FromBaseResponse is NewTestResponse under the name that reads better at a call site building one from a response already in hand.

func NewTestResponse

func NewTestResponse(t T, response *http.Response, request *http.Request) *TestResponse

NewTestResponse wraps a response and the request that produced it.

The body is read here and closed, because it is a stream that can be read once and every assertion below reads it.

The request is what the session, the URL resolution and the view are read through, so an assertion that needs one says so rather than reaching for an ambient request.

func (*TestResponse) AssertAccepted

func (r *TestResponse) AssertAccepted() *TestResponse

AssertAccepted asserts a 202 status.

func (*TestResponse) AssertBadRequest

func (r *TestResponse) AssertBadRequest() *TestResponse

AssertBadRequest asserts a 400 status.

func (*TestResponse) AssertConflict

func (r *TestResponse) AssertConflict() *TestResponse

AssertConflict asserts a 409 status.

func (*TestResponse) AssertContent

func (r *TestResponse) AssertContent(value string) *TestResponse

AssertContent asserts the body is exactly this.

func (*TestResponse) AssertCookie

func (r *TestResponse) AssertCookie(cookieName string, value ...any) *TestResponse

AssertCookie asserts the cookie is there and, when a value is given, decrypts to it.

Passing nothing asserts only that the cookie is there; passing a value asserts what it holds, decrypting first.

func (*TestResponse) AssertCookieExpired

func (r *TestResponse) AssertCookieExpired(cookieName string) *TestResponse

AssertCookieExpired asserts the cookie is there and its expiry is in the past.

func (*TestResponse) AssertCookieMissing

func (r *TestResponse) AssertCookieMissing(cookieName string) *TestResponse

AssertCookieMissing asserts the cookie is not on the response.

func (*TestResponse) AssertCookieNotExpired

func (r *TestResponse) AssertCookieNotExpired(cookieName string) *TestResponse

AssertCookieNotExpired asserts the cookie is there and its expiry is unset or in the future.

func (*TestResponse) AssertCreated

func (r *TestResponse) AssertCreated() *TestResponse

AssertCreated asserts a 201 status.

func (*TestResponse) AssertDontSee

func (r *TestResponse) AssertDontSee(value any, escape ...bool) *TestResponse

AssertDontSee asserts the text is not on the page.

It is the half people skip and the half that catches a leak: a draft in a public listing, an address on a page that should not name one, a button somebody without the permission can see.

func (*TestResponse) AssertDontSeeHTML

func (r *TestResponse) AssertDontSeeHTML(value any) *TestResponse

AssertDontSeeHTML is TestResponse.AssertDontSee without the escaping.

func (*TestResponse) AssertDontSeeText

func (r *TestResponse) AssertDontSeeText(value any, escape ...bool) *TestResponse

AssertDontSeeText asserts the text is not on the page once the tags are taken off.

func (*TestResponse) AssertDownload

func (r *TestResponse) AssertDownload(filename ...string) *TestResponse

AssertDownload asserts the response offers a file download, and that it carries the given filename when one is given.

func (*TestResponse) AssertExactJSON

func (r *TestResponse) AssertExactJSON(data any) *TestResponse

AssertExactJSON asserts the payload is exactly this, key for key.

func (*TestResponse) AssertExactJSONStructure

func (r *TestResponse) AssertExactJSONStructure(structure any, responseData ...any) *TestResponse

AssertExactJSONStructure asserts the payload has the keys the structure names and no others.

func (*TestResponse) AssertForbidden

func (r *TestResponse) AssertForbidden() *TestResponse

AssertForbidden asserts a 403 status.

func (*TestResponse) AssertFound

func (r *TestResponse) AssertFound() *TestResponse

AssertFound asserts a 302 status.

func (*TestResponse) AssertGone

func (r *TestResponse) AssertGone() *TestResponse

AssertGone asserts a 410 status.

func (*TestResponse) AssertHeader

func (r *TestResponse) AssertHeader(headerName string, value ...any) *TestResponse

AssertHeader asserts the header is present, and holds the value too when one is given. At most one value may be given, and a nil one checks only presence.

func (*TestResponse) AssertHeaderMissing

func (r *TestResponse) AssertHeaderMissing(headerName string) *TestResponse

AssertHeaderMissing asserts the header is not present.

func (*TestResponse) AssertInternalServerError

func (r *TestResponse) AssertInternalServerError() *TestResponse

AssertInternalServerError asserts a 500 status.

func (*TestResponse) AssertInvalid

func (r *TestResponse) AssertInvalid(errors any, errorBag string, responseKey string) *TestResponse

AssertInvalid asserts these fields were rejected, and that the message about each contains what was named.

A JSON response is handed to TestResponse.AssertJSONValidationErrors instead, reading responseKey, which defaults to "errors".

func (*TestResponse) AssertJSON

func (r *TestResponse) AssertJSON(value any, strict ...bool) *TestResponse

AssertJSON asserts the response carries at least this. Passing strict as true asks for an exact match instead.

See the doc comment on fluent.FromAssertableJSONString.

func (*TestResponse) AssertJSONCount

func (r *TestResponse) AssertJSONCount(count int, key ...string) *TestResponse

AssertJSONCount asserts the payload, or what is at the given dot path, has the expected number of entries.

func (*TestResponse) AssertJSONFragment

func (r *TestResponse) AssertJSONFragment(data any) *TestResponse

AssertJSONFragment asserts the given key/value pairs appear somewhere in the payload.

func (*TestResponse) AssertJSONFragments

func (r *TestResponse) AssertJSONFragments(data []any) *TestResponse

AssertJSONFragments asserts each fragment appears somewhere in the payload.

func (*TestResponse) AssertJSONIsArray

func (r *TestResponse) AssertJSONIsArray(key ...string) *TestResponse

AssertJSONIsArray asserts what is at the key is a JSON array.

func (*TestResponse) AssertJSONIsObject

func (r *TestResponse) AssertJSONIsObject(key ...string) *TestResponse

AssertJSONIsObject asserts what is at the key is a JSON object.

func (*TestResponse) AssertJSONMissing

func (r *TestResponse) AssertJSONMissing(data any, exact ...bool) *TestResponse

AssertJSONMissing asserts the payload does not carry this. Passing exact as true compares the fragment whole rather than pair by pair.

func (*TestResponse) AssertJSONMissingExact

func (r *TestResponse) AssertJSONMissingExact(data any) *TestResponse

AssertJSONMissingExact asserts the payload does not carry this fragment whole.

func (*TestResponse) AssertJSONMissingPath

func (r *TestResponse) AssertJSONMissingPath(path string) *TestResponse

AssertJSONMissingPath asserts nothing is at the dot path.

func (*TestResponse) AssertJSONMissingValidationErrors

func (r *TestResponse) AssertJSONMissingValidationErrors(keys any, responseKey ...string) *TestResponse

AssertJSONMissingValidationErrors asserts none of these fields was rejected. A nil argument asserts there were no validation errors at all, and an empty body passes.

func (*TestResponse) AssertJSONPath

func (r *TestResponse) AssertJSONPath(path string, expect any) *TestResponse

AssertJSONPath asserts the value at the dot path is the one expected.

func (*TestResponse) AssertJSONPathCanonicalizing

func (r *TestResponse) AssertJSONPathCanonicalizing(path string, expect any) *TestResponse

AssertJSONPathCanonicalizing asserts the value at the dot path is the one expected once both sides are sorted, so order does not count.

func (*TestResponse) AssertJSONStructure

func (r *TestResponse) AssertJSONStructure(structure any, responseData ...any) *TestResponse

AssertJSONStructure asserts the payload has the keys the structure names. Other keys are allowed.

How a structure is written is on AssertableJSONString.AssertStructure.

func (*TestResponse) AssertJSONValidationErrorFor

func (r *TestResponse) AssertJSONValidationErrorFor(key string, responseKey ...string) *TestResponse

AssertJSONValidationErrorFor asserts the payload rejected this one field.

func (*TestResponse) AssertJSONValidationErrors

func (r *TestResponse) AssertJSONValidationErrors(errors any, responseKey ...string) *TestResponse

AssertJSONValidationErrors asserts the payload rejected these fields, and said these things about them.

"email"                                    the field was rejected
[]string{"email", "name"}                  both were
map[string]any{"email": "must be unique"}  and this is in the message

func (*TestResponse) AssertLocation

func (r *TestResponse) AssertLocation(uri string) *TestResponse

AssertLocation asserts the Location header points at the given URI, compared as absolute URLs.

func (*TestResponse) AssertMethodNotAllowed

func (r *TestResponse) AssertMethodNotAllowed() *TestResponse

AssertMethodNotAllowed asserts a 405 status.

func (*TestResponse) AssertMovedPermanently

func (r *TestResponse) AssertMovedPermanently() *TestResponse

AssertMovedPermanently asserts a 301 status.

func (*TestResponse) AssertNoContent

func (r *TestResponse) AssertNoContent(status ...int) *TestResponse

AssertNoContent asserts the status -- 204 unless another is given -- and an empty body.

func (*TestResponse) AssertNotAcceptable

func (r *TestResponse) AssertNotAcceptable() *TestResponse

AssertNotAcceptable asserts a 406 status.

func (*TestResponse) AssertNotFound

func (r *TestResponse) AssertNotFound() *TestResponse

AssertNotFound asserts a 404 status.

func (*TestResponse) AssertNotModified

func (r *TestResponse) AssertNotModified() *TestResponse

AssertNotModified asserts a 304 status.

func (*TestResponse) AssertNotStreamed

func (r *TestResponse) AssertNotStreamed() *TestResponse

AssertNotStreamed asserts the response was not streamed.

func (*TestResponse) AssertOK

func (r *TestResponse) AssertOK() *TestResponse

AssertOK asserts a 200 status.

func (*TestResponse) AssertOnlyInvalid

func (r *TestResponse) AssertOnlyInvalid(errors any, errorBag string, responseKey string) *TestResponse

AssertOnlyInvalid asserts these fields have errors and no others do.

It is the half TestResponse.AssertInvalid is not. A rule that rejects one field too many passes AssertInvalid, because the field it was asked about is in the list.

func (*TestResponse) AssertOnlyJSONValidationErrors

func (r *TestResponse) AssertOnlyJSONValidationErrors(errors any, responseKey ...string) *TestResponse

AssertOnlyJSONValidationErrors asserts these fields were rejected and no others.

func (*TestResponse) AssertPaymentRequired

func (r *TestResponse) AssertPaymentRequired() *TestResponse

AssertPaymentRequired asserts a 402 status.

func (*TestResponse) AssertPermanentRedirect

func (r *TestResponse) AssertPermanentRedirect() *TestResponse

AssertPermanentRedirect asserts a 308 status.

func (*TestResponse) AssertPlainCookie

func (r *TestResponse) AssertPlainCookie(cookieName string, value ...any) *TestResponse

AssertPlainCookie asserts the cookie is there and holds the value, unencrypted.

func (*TestResponse) AssertRedirect

func (r *TestResponse) AssertRedirect(uri ...string) *TestResponse

AssertRedirect asserts a redirect status, and the location too when one is given. At most one location may be given.

func (*TestResponse) AssertRedirectBack

func (r *TestResponse) AssertRedirectBack() *TestResponse

AssertRedirectBack asserts a redirect to the previous location. It needs TestResponse.URL to know where back is, and says so when it is missing.

func (*TestResponse) AssertRedirectContains

func (r *TestResponse) AssertRedirectContains(uri string) *TestResponse

AssertRedirectContains asserts a redirect status whose location contains the given text.

func (*TestResponse) AssertRedirectToRoute

func (r *TestResponse) AssertRedirectToRoute(name string, parameters ...map[string]any) *TestResponse

AssertRedirectToRoute asserts a redirect to the named route, built with the parameters given. It needs TestResponse.URL to turn the name into a URL.

func (*TestResponse) AssertRedirectToSignedRoute

func (r *TestResponse) AssertRedirectToSignedRoute(name string, parameters map[string]any, absolute bool) *TestResponse

AssertRedirectToSignedRoute asserts a redirect to a route whose signature is valid, and to the named route too when a name is given. An empty name checks only the signature. It needs TestResponse.URL to check the signature.

func (*TestResponse) AssertRequestTimeout

func (r *TestResponse) AssertRequestTimeout() *TestResponse

AssertRequestTimeout asserts a 408 status.

func (*TestResponse) AssertSee

func (r *TestResponse) AssertSee(value any, escape ...bool) *TestResponse

AssertSee asserts the text is on the page. The text is HTML-escaped first unless escape is given as false.

func (*TestResponse) AssertSeeHTML

func (r *TestResponse) AssertSeeHTML(value any) *TestResponse

AssertSeeHTML is TestResponse.AssertSee without the escaping.

func (*TestResponse) AssertSeeHTMLInOrder

func (r *TestResponse) AssertSeeHTMLInOrder(values []string) *TestResponse

AssertSeeHTMLInOrder is TestResponse.AssertSeeInOrder without the escaping.

func (*TestResponse) AssertSeeInOrder

func (r *TestResponse) AssertSeeInOrder(values []string, escape ...bool) *TestResponse

AssertSeeInOrder asserts the strings are on the page, each after the last.

It is the assertion three AssertSee calls are not: they pass on a page that shows the three in any order, and "the total is under the line items" is an order.

func (*TestResponse) AssertSeeText

func (r *TestResponse) AssertSeeText(value any, escape ...bool) *TestResponse

AssertSeeText asserts the text is on the page once the tags are taken off.

It is the one to reach for when the words are broken up by markup: "Hello <b>Alice</b>" contains "Hello Alice" only after the tags are gone.

func (*TestResponse) AssertSeeTextInOrder

func (r *TestResponse) AssertSeeTextInOrder(values []string, escape ...bool) *TestResponse

AssertSeeTextInOrder asserts the strings are on the page once the tags are taken off, each after the last.

func (*TestResponse) AssertServerError

func (r *TestResponse) AssertServerError() *TestResponse

AssertServerError asserts a status in the 5xx range.

func (*TestResponse) AssertServiceUnavailable

func (r *TestResponse) AssertServiceUnavailable() *TestResponse

AssertServiceUnavailable asserts a 503 status.

func (*TestResponse) AssertSessionDoesntHaveErrors

func (r *TestResponse) AssertSessionDoesntHaveErrors(keys any, format string, errorBag string) *TestResponse

AssertSessionDoesntHaveErrors asserts these fields were not rejected.

With no keys it is TestResponse.AssertSessionHasNoErrors. With keys it asserts about those fields only, and a response that produced no errors at all passes.

func (*TestResponse) AssertSessionHas

func (r *TestResponse) AssertSessionHas(key any, value ...any) *TestResponse

AssertSessionHas asserts the session holds the key, and the value too when one is given.

Passing no value asserts only that the key is there. A value of func(any) bool is called with what is stored and must report true. A key that is really a set of bindings is handed to TestResponse.AssertSessionHasAll.

func (*TestResponse) AssertSessionHasAll

func (r *TestResponse) AssertSessionHasAll(bindings map[string]any) *TestResponse

AssertSessionHasAll asserts the session holds every one of these bindings.

A nil value asks only that the key is there, which is the same nil TestResponse.AssertSessionHas reads as "no value given". Keys are walked in sorted order, so a failure message is stable.

func (*TestResponse) AssertSessionHasErrors

func (r *TestResponse) AssertSessionHasErrors(keys any, format string, errorBag string) *TestResponse

AssertSessionHasErrors asserts these fields were rejected, and that the message about each contains what was named.

format and errorBag are two named parameters rather than one variadic, because they are two different things and a caller passing one string should not have to guess which.

The flash carries one bag, so any errorBag other than the default finds it empty. session.Flash says why -- what it carries is what one rejected request produced.

func (*TestResponse) AssertSessionHasErrorsIn

func (r *TestResponse) AssertSessionHasErrorsIn(errorBag string, keys any, format string) *TestResponse

AssertSessionHasErrorsIn is TestResponse.AssertSessionHasErrors with the bag named first.

func (*TestResponse) AssertSessionHasInput

func (r *TestResponse) AssertSessionHasInput(key any, value ...any) *TestResponse

AssertSessionHasInput asserts the old input holds the key, and the value too when one is given.

The old input is on the flash cookie the rejected request wrote, so TestResponse.Flash has to be set.

key and value carry the same three shapes TestResponse.AssertSessionHas takes.

func (*TestResponse) AssertSessionHasNoErrors

func (r *TestResponse) AssertSessionHasNoErrors() *TestResponse

AssertSessionHasNoErrors asserts nothing was rejected.

The failure prints every bag it found, because "the session has errors" is not an answer anybody can act on and the message that follows it is.

func (*TestResponse) AssertSessionMissing

func (r *TestResponse) AssertSessionMissing(key any) *TestResponse

AssertSessionMissing asserts the session does not hold the key, or any of them when a list is given.

func (*TestResponse) AssertSimilarJSON

func (r *TestResponse) AssertSimilarJSON(data any) *TestResponse

AssertSimilarJSON asserts the payload is this once both sides are sorted, so the order of a list does not count.

func (*TestResponse) AssertStatus

func (r *TestResponse) AssertStatus(status int) *TestResponse

AssertStatus asserts the status is the one expected.

func (*TestResponse) AssertStreamed

func (r *TestResponse) AssertStreamed() *TestResponse

AssertStreamed asserts the response was streamed.

It reads two signals: what the handler recorded on TestResponse.Streamed, and the chunked transfer encoding a streamed body arrives under.

func (*TestResponse) AssertStreamedContent

func (r *TestResponse) AssertStreamedContent(value string) *TestResponse

AssertStreamedContent asserts the streamed body is exactly this.

func (*TestResponse) AssertStreamedJSONContent

func (r *TestResponse) AssertStreamedJSONContent(value any) *TestResponse

AssertStreamedJSONContent asserts the streamed body is that value encoded.

func (*TestResponse) AssertSuccessful

func (r *TestResponse) AssertSuccessful() *TestResponse

AssertSuccessful asserts a status in the 2xx range.

func (*TestResponse) AssertSuccessfulPrecognition

func (r *TestResponse) AssertSuccessfulPrecognition() *TestResponse

AssertSuccessfulPrecognition asserts an empty 204 carrying a Precognition-Success header set to "true".

func (*TestResponse) AssertTemporaryRedirect

func (r *TestResponse) AssertTemporaryRedirect() *TestResponse

AssertTemporaryRedirect asserts a 307 status.

func (*TestResponse) AssertTooManyRequests

func (r *TestResponse) AssertTooManyRequests() *TestResponse

AssertTooManyRequests asserts a 429 status.

func (*TestResponse) AssertUnauthorized

func (r *TestResponse) AssertUnauthorized() *TestResponse

AssertUnauthorized asserts a 401 status.

func (*TestResponse) AssertUnprocessable

func (r *TestResponse) AssertUnprocessable() *TestResponse

AssertUnprocessable asserts a 422 status.

func (*TestResponse) AssertUnsupportedMediaType

func (r *TestResponse) AssertUnsupportedMediaType() *TestResponse

AssertUnsupportedMediaType asserts a 415 status.

func (*TestResponse) AssertValid

func (r *TestResponse) AssertValid(keys any, errorBag string, responseKey string) *TestResponse

AssertValid asserts these fields were not rejected, and with nil keys that nothing was.

A JSON response is handed to TestResponse.AssertJSONMissingValidationErrors instead, reading responseKey, which defaults to "errors".

func (*TestResponse) AssertViewHas

func (r *TestResponse) AssertViewHas(key any, value ...any) *TestResponse

AssertViewHas asserts the view was bound this key, and this value when one is given.

Passing no value asserts only that the key is there. A value of func(any) bool is called with what was bound and must report true. A key that is really a set of bindings is handed to TestResponse.AssertViewHasAll.

func (*TestResponse) AssertViewHasAll

func (r *TestResponse) AssertViewHasAll(bindings map[string]any) *TestResponse

AssertViewHasAll asserts the view was bound every one of these. A nil value asks only that the key is there.

func (*TestResponse) AssertViewIs

func (r *TestResponse) AssertViewIs(value string) *TestResponse

AssertViewIs asserts the handler rendered that view and not another.

func (*TestResponse) AssertViewMissing

func (r *TestResponse) AssertViewMissing(key string) *TestResponse

AssertViewMissing asserts the view was not bound this key.

func (*TestResponse) Collect

func (r *TestResponse) Collect(key ...string) collections.Collection[any]

Collect returns what is at the given dot path as a collection.

collections.Collection is a slice, so an object at the path comes back as its values in key order and a list comes back as itself -- which is what the assertion this feeds is about either way.

func (*TestResponse) Content

func (r *TestResponse) Content() string

Content is TestResponse.GetContent under a shorter name.

func (*TestResponse) DDBody

func (r *TestResponse) DDBody(key ...string) *TestResponse

DDBody logs the body and stops the test.

func (*TestResponse) DDHeaders

func (r *TestResponse) DDHeaders() *TestResponse

DDHeaders logs the response headers and stops the test.

Ending the process would take every other test with it, so this ends the test instead: the dump is printed and the test stops where the call is.

func (*TestResponse) DDJSON

func (r *TestResponse) DDJSON(key ...string) *TestResponse

DDJSON logs the decoded payload and stops the test.

func (*TestResponse) DDSession

func (r *TestResponse) DDSession(keys ...string) *TestResponse

DDSession logs the session and stops the test.

func (*TestResponse) DecodeResponseJSON

func (r *TestResponse) DecodeResponseJSON() *AssertableJSONString

DecodeResponseJSON decodes the body and returns it as an AssertableJSONString.

A body that is not JSON is a failure here rather than three assertions later, and when the request logged an exception that exception is what the failure says: a route that threw answers with a stack trace or an error page, and "Invalid JSON was returned from the route" is the least useful true sentence about it.

func (*TestResponse) Dump

func (r *TestResponse) Dump(key ...string) *TestResponse

Dump logs the body, decoded and indented when it is JSON. A key logs only that part of the payload.

func (*TestResponse) DumpHeaders

func (r *TestResponse) DumpHeaders() *TestResponse

DumpHeaders logs the response headers.

func (*TestResponse) DumpSession

func (r *TestResponse) DumpSession(keys ...string) *TestResponse

DumpSession logs the session, or only the given keys when there are any. It logs nothing when the response carries no session.

func (*TestResponse) GetContent

func (r *TestResponse) GetContent() string

GetContent returns the body, which was read once when the response was wrapped.

func (*TestResponse) GetCookie

func (r *TestResponse) GetCookie(cookieName string, decrypt, unserialize bool) *http.Cookie

GetCookie returns the named cookie, or nil when it is not on the response.

decrypt needs the Encrypter. Without one the test is told to set it rather than handed the ciphertext, because an assertion comparing a value against ciphertext fails for a response that is right.

func (*TestResponse) GetStatusCode

func (r *TestResponse) GetStatusCode() int

GetStatusCode returns the status, or 0 when there is no response.

func (*TestResponse) Headers

func (r *TestResponse) Headers() http.Header

Headers returns the response headers, or an empty set when there is no response.

func (*TestResponse) JSON

func (r *TestResponse) JSON(key ...string) any

JSON returns the decoded payload, or the part of it at the given dot path. At most one path may be given.

func (*TestResponse) OffsetExists

func (r *TestResponse) OffsetExists(offset string) bool

OffsetExists reports whether the key is in the view's data, or failing that in the decoded JSON body.

It is one of the four Offset methods, which are how a test reaches for a value by key.

func (*TestResponse) OffsetGet

func (r *TestResponse) OffsetGet(offset string) any

OffsetGet returns the view's data at the key, or the decoded JSON body's.

func (*TestResponse) OffsetSet

func (r *TestResponse) OffsetSet(offset string, value any)

OffsetSet always fails the test: a response is what came back, and there is nothing to write to.

It fails rather than doing nothing, because a test that reached here has a bug in it and carrying on would hide where.

func (*TestResponse) OffsetUnset

func (r *TestResponse) OffsetUnset(offset string)

OffsetUnset always fails the test, for the same reason TestResponse.OffsetSet does.

func (*TestResponse) StreamedContent

func (r *TestResponse) StreamedContent() string

StreamedContent returns the streamed body.

The body was already read off the wire by NewTestResponse, so it is simply the body.

func (*TestResponse) ViewData

func (r *TestResponse) ViewData(key string) any

ViewData returns one value the handler passed to the view, for an assertion this type does not have.

func (*TestResponse) WithExceptions

func (r *TestResponse) WithExceptions(exceptions LoggedExceptionCollection) *TestResponse

WithExceptions sets what the request logged, which a failure message then carries. It returns the response.

type TestView

type TestView struct {
	// contains filtered or unexported fields
}

TestView is a view that has been drawn, with the assertions worth making about the HTML it produced and about the data it was handed.

AssertSee and the rest read the rendered HTML; AssertViewHas and the rest read the view's gathered data, which is the only place a binding the template never printed is still visible.

Every assertion returns the view.

rendered.AssertViewHas("user").AssertSee("Alice").AssertDontSee("Draft")

func NewTestView

func NewTestView(t T, v *view.View) (*TestView, error)

NewTestView renders the view and wraps it for assertion.

It returns an error for a nil view and for a view that would not render, so a template failure is reported where it happened rather than as an empty page three assertions later.

func (*TestView) AssertDontSee

func (v *TestView) AssertDontSee(value string, escape ...bool) *TestView

AssertDontSee asserts the text is not in the rendered view.

func (*TestView) AssertDontSeeText

func (v *TestView) AssertDontSeeText(value string, escape ...bool) *TestView

AssertDontSeeText asserts the text is not in the rendered view once the tags are taken off.

func (*TestView) AssertSee

func (v *TestView) AssertSee(value string, escape ...bool) *TestView

AssertSee asserts the text is in the rendered view. The text is HTML-escaped first unless escape is given as false.

func (*TestView) AssertSeeInOrder

func (v *TestView) AssertSeeInOrder(values []string, escape ...bool) *TestView

AssertSeeInOrder asserts the strings are in the rendered view, each one after the last.

func (*TestView) AssertSeeText

func (v *TestView) AssertSeeText(value string, escape ...bool) *TestView

AssertSeeText asserts the text is in the rendered view once the tags are taken off.

It is the one to reach for when markup breaks the words up: "Hello <b>Alice</b>" contains "Hello Alice" only after the tags are gone.

func (*TestView) AssertSeeTextInOrder

func (v *TestView) AssertSeeTextInOrder(values []string, escape ...bool) *TestView

AssertSeeTextInOrder asserts the strings are in the rendered view once the tags are taken off, each one after the last.

func (*TestView) AssertViewEmpty

func (v *TestView) AssertViewEmpty() *TestView

AssertViewEmpty asserts the view drew nothing.

func (*TestView) AssertViewHas

func (v *TestView) AssertViewHas(key any, value ...any) *TestView

AssertViewHas asserts the view was bound this piece of data, and this value when one is given.

A value of func(any) bool is handed the binding and must report true. Anything else is compared loosely. A key that is really a set of bindings is handed to TestView.AssertViewHasAll.

func (*TestView) AssertViewHasAll

func (v *TestView) AssertViewHasAll(bindings any) *TestView

AssertViewHasAll asserts every one of these bindings is there.

The bindings are a map[string]any for name and value, or a []string or []any for names alone. Anything else fails the test.

Map keys are visited in sorted order, so that a run that fails names the same binding every time.

func (*TestView) AssertViewMissing

func (v *TestView) AssertViewMissing(key string) *TestView

AssertViewMissing asserts the view was not bound this piece of data.

func (*TestView) ToString

func (v *TestView) ToString() string

ToString returns the rendered view.

Directories

Path Synopsis
Package concerns is empty, and it stays empty.
Package concerns is empty, and it stays empty.
Package constraints holds the reusable matchers the assertions evaluate.
Package constraints holds the reusable matchers the assertions evaluate.
Package exceptions holds the errors an assertion returns when it was called wrongly.
Package exceptions holds the errors an assertion returns when it was called wrongly.
Package fluent asserts about a JSON payload one property at a time.
Package fluent asserts about a JSON payload one property at a time.
concerns
Package concerns is empty, and it stays empty.
Package concerns is empty, and it stays empty.

Jump to

Keyboard shortcuts

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