http

package
v0.0.0-...-4c78a19 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunOneWith

func RunOneWith(r TesterApi, basename string, callback func() (*http.Request, error)) error

Run initializes the tester, runs a test, and closes it, calling Fatalf on any error.

func RunTestWith

func RunTestWith(r TesterApi, basename string, callback func() (*http.Request, error)) error

RunTestWith runs a test using the specified basename and callback. This can be used multiple times within a Tester. The tester state is maintained across tests, allowing a sequence of calls that builds up and modifies tester state.

Types

type Tester

type Tester struct {
	goldenbase.Tester

	CreateHandler func(r *Tester) http.Handler
	Callback      func() (*http.Request, error)
}

Tester provides the structure for running API unit tests. For a single test, the typical calling sequence is:

r := NewTester(handlerCreateFunc)
if err := r.Run(t, basename, callback); err != nil { t.Fatal(err) }

For multiple tests, maintaining the Tester state across tests as it changes:

r := NewTester(handlerCreateFunc)
if err := r.Init(); err != nil { t.Fatal(err) }
if err := r.RunTestWith(t, basename, callback); err != nil { t.Fatal(err) }
if err := r.RunTestWith(t, basename2, callback2); err != nil { t.Fatal(err) }
if err := r.Close(); err != nil { t.Fatal(err) }

(Error handling should be better than the minimal error handling shown above.)

func NewTester

func NewTester(createHandler func(r *Tester) http.Handler) *Tester

NewTester creates a new instance of a Tester that will use the specified function to create an http.Handler.

func (*Tester) Act

func (r *Tester) Act() error

Act sets up the handler, calls the request, and records the result to the output file.

func (*Tester) SetBaseNameAndCallback

func (r *Tester) SetBaseNameAndCallback(basename string, callback func() (*http.Request, error))

SetBaseNameAndCallback resets the basename and callback of the Tester in preparation for running a test.

type TesterApi

type TesterApi interface {
	goldenbase.MultiRunner
	SetBaseNameAndCallback(basename string, callback func() (*http.Request, error))
}

Jump to

Keyboard shortcuts

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