autopilot

package module
v2023.12.7 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 13 Imported by: 0

README

autopilot

A golang testing utils library

Go Reference

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Mux       *http.ServeMux
	Server    *httptest.Server
	Templater *FixtureTemplater
)

Functions

func Assert

func Assert(tb testing.TB, condition bool, msg string, v ...interface{})

Assert fails the test if the condition is false.

func Equals

func Equals(tb testing.TB, exp, act interface{})

Equals fails the test if exp is not equal to act.

func Fixture

func Fixture(path string) string

Load testdata/fixtures/<path> and return as string

func NewHttpClient

func NewHttpClient(fn RoundTripFunc) *http.Client

Returns a Mock'd HttpClient

func Ok

func Ok(tb testing.TB, err error)

Ok fails the test if an err is not nil.

func Register added in v2023.12.6

func Register[T any](name string, value T) T

func RegisterEndpoint

func RegisterEndpoint(endpoint string, responseWriter ResponseWriter, requestValidation RequestValidation) string

func RegisterPaginatedEndpoint added in v2023.12.7

func RegisterPaginatedEndpoint(t *testing.T, url string, requests ...TestRequest) string

func RunTableTests added in v2023.11.2

func RunTableTests[T any](t *testing.T, cases map[string]T, fn func(*testing.T, T))

RunTableTests runs a table of tests calling `fn` for each test and ensuring all tests run in parallel using goroutines

func Setup

func Setup() func()

Setup an HttpTestServer and ServerMux (for path routing) and return the teardown function

func TemplatedFixture

func TemplatedFixture(fixture string) string

func ToJson

func ToJson(query GraphqlQuery) string

Types

type FixtureTemplater

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

func NewFixtureTemplater

func NewFixtureTemplater(templateDirs ...string) *FixtureTemplater

NewFixtureTemplater creates a FixtureTemplater using the templates load from the passed in templateDir

If no templateDir is passed in then ./testdata/templates is used

func (*FixtureTemplater) ParseToBytes added in v2023.12.7

func (t *FixtureTemplater) ParseToBytes(contents string) (*bytes.Buffer, error)

func (*FixtureTemplater) Use

func (t *FixtureTemplater) Use(contents string) (string, error)

func (*FixtureTemplater) UseFile

func (t *FixtureTemplater) UseFile(path string) (string, error)

func (*FixtureTemplater) UseKey

func (t *FixtureTemplater) UseKey(key string) (string, error)

type GraphqlQuery

type GraphqlQuery struct {
	Query     string
	Variables map[string]interface{} `json:",omitempty"`
}

func GraphQLQueryFixture

func GraphQLQueryFixture(fixture string) GraphqlQuery

func Parse

func Parse(r *http.Request) GraphqlQuery

type RequestValidation

type RequestValidation func(*http.Request)

func GraphQLQueryFixtureValidation

func GraphQLQueryFixtureValidation(t *testing.T, fixture string) RequestValidation

func GraphQLQueryToJsonValidation added in v2023.12.6

func GraphQLQueryToJsonValidation(t *testing.T, request GraphqlQuery) RequestValidation

func GraphQLQueryValidation

func GraphQLQueryValidation(t *testing.T, exp string) RequestValidation

func SkipRequestValidation

func SkipRequestValidation() RequestValidation

func TestRequestValidation added in v2023.12.7

func TestRequestValidation(t *testing.T, request TestRequest) RequestValidation

type ResponseWriter

type ResponseWriter func(http.ResponseWriter)

func EmptyResponse

func EmptyResponse() ResponseWriter

func FixtureResponse

func FixtureResponse(fixture string) ResponseWriter

func JsonStringResponse added in v2023.12.6

func JsonStringResponse(jsonString string) ResponseWriter

func TestRequestResponse added in v2023.12.7

func TestRequestResponse(testRequest TestRequest) ResponseWriter

type RoundTripFunc

type RoundTripFunc func(req *http.Request) *http.Response

func (RoundTripFunc) RoundTrip

func (f RoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error)

type TestRequest added in v2023.12.6

type TestRequest struct {
	Request  GraphqlQuery
	Response map[string]any
}

func NewTestRequest added in v2023.12.6

func NewTestRequest(request string, variables string, response string) TestRequest

func (*TestRequest) ResponseAsString added in v2023.12.7

func (t *TestRequest) ResponseAsString() string

Jump to

Keyboard shortcuts

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