gobbi

package module
v0.0.0-...-d291526 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

README

gobbi is a port of gabbi from Python to go.

It's capable of testing itself, so far, but that's about it for now. Watch this space.

Documentation

Index

Constants

View Source
const (
	// TODO: change this
	DefaultHTTPTimeout = 30
)

Variables

View Source
var (
	ErrTestError                   = errors.New("error during request")
	ErrTestFailure                 = errors.New("failure during request")
	ErrUnexpectedStatus            = fmt.Errorf("%w: unexpected status", ErrTestFailure)
	ErrNoDataHandler               = fmt.Errorf("%w: no handler for request content-type", ErrTestError)
	ErrDataHandlerContentMismatch  = fmt.Errorf("%w: data and request content-type mismatch", ErrTestError)
	ErrStringNotFound              = fmt.Errorf("%w: string not found in body", ErrTestFailure)
	ErrJSONPathNotMatched          = fmt.Errorf("%w: json path not matched", ErrTestFailure)
	ErrNoPriorTest                 = fmt.Errorf("%w: no prior test", ErrTestError)
	ErrHeaderNotPresent            = fmt.Errorf("%w: missing header", ErrTestFailure)
	ErrHeaderValueMismatch         = fmt.Errorf("%w: header value mismatch", ErrTestFailure)
	ErrEnvironmentVariableNotFound = fmt.Errorf("%w: environment variable not found", ErrTestError)
)

TODO: Maybe Test instead of Request? Not sure what I was thinking...

Functions

func StringReplace

func StringReplace(c *Case, in string) (string, error)

Types

type BaseClient

type BaseClient struct {
	Client *http.Client
}

func NewClient

func NewClient() *BaseClient

func (*BaseClient) Do

func (b *BaseClient) Do(c *Case)

func (*BaseClient) ExecuteOne

func (b *BaseClient) ExecuteOne(c *Case)

type BaseResponseHandler

type BaseResponseHandler struct{}

func (*BaseResponseHandler) Accepts

func (b *BaseResponseHandler) Accepts(c *Case) bool

type BaseStringReplacer

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

func (*BaseStringReplacer) GetRegExp

func (br *BaseStringReplacer) GetRegExp() *regexp.Regexp

func (*BaseStringReplacer) Resolve

func (br *BaseStringReplacer) Resolve(prior *Case, in, cast string) (string, error)

type BinaryDataHandler

type BinaryDataHandler struct{}

func (*BinaryDataHandler) GetBody

func (t *BinaryDataHandler) GetBody(c *Case) (io.Reader, error)

type Case

type Case struct {
	Name            string                 `yaml:"name,omitempty"`
	Desc            string                 `yaml:"desc,omitempty"`
	Method          string                 `yaml:"method,omitempty"`
	URL             string                 `yaml:"url,omitempty"`
	GET             string                 `yaml:"GET,omitempty"`
	POST            string                 `yaml:"POST,omitempty"`
	PUT             string                 `yaml:"PUT,omitempty"`
	DELETE          string                 `yaml:"DELETE,omitempty"`
	HEAD            string                 `yaml:"HEAD,omitempty"`
	PATCH           string                 `yaml:"PATCH,omitempty"`
	OPTIONS         string                 `yaml:"OPTIONS,omitempty"`
	Status          int                    `yaml:"status,omitempty"`
	RequestHeaders  map[string]string      `yaml:"request_headers,omitempty"`
	QueryParameters map[string]interface{} `yaml:"query_parameters,omitempty"`
	Data            interface{}            `yaml:"data,omitempty"`
	Xfail           bool                   `yaml:"xfail,omitempty"`
	Verbose         bool                   `yaml:"verbose,omitempty"`
	Skip            *string                `yaml:"skip,omitempty"`
	CertValidated   bool                   `yaml:"cert_validated,omitempty"`
	Redirects       int                    `yaml:"redirects,omitempty"`
	UsePriorTest    *bool                  `yaml:"use_prior_test,omitempty"`
	Poll            Poll                   `yaml:"poll,omitempty"`
	// SSL is ignored but we parse it for compatibility with gabbi.
	SSL *bool `yaml:"ssl,omitempty"`
	// TODO: Ideally these would be pluggable, as with gabbi, but it is too
	// hard to figure out how to do that, so we'll fake it for now.
	ResponseHeaders          map[string]string      `yaml:"response_headers,omitempty"`
	ResponseForbiddenHeaders []string               `yaml:"response_forbidden_headers,omitempty"`
	ResponseStrings          []string               `yaml:"response_strings,omitempty"`
	ResponseJSONPaths        map[string]interface{} `yaml:"response_json_paths,omitempty"`
	// contains filtered or unexported fields
}

func (*Case) Done

func (c *Case) Done() bool

func (*Case) Errorf

func (c *Case) Errorf(format string, args ...any)

func (*Case) Fatalf

func (c *Case) Fatalf(format string, args ...any)

func (*Case) GetDefaultURLBase

func (c *Case) GetDefaultURLBase() string

func (*Case) GetParent

func (c *Case) GetParent() *testing.T

func (*Case) GetPrior

func (c *Case) GetPrior(caseName string) *Case

func (*Case) GetRequestBody

func (c *Case) GetRequestBody() (io.Reader, error)

func (*Case) GetResponseBody

func (c *Case) GetResponseBody() io.ReadSeeker

func (*Case) GetResponseHeader

func (c *Case) GetResponseHeader() http.Header

func (*Case) GetTest

func (c *Case) GetTest() *testing.T

func (*Case) GetXFailure

func (c *Case) GetXFailure() bool

func (*Case) NewRequestDataHandler

func (c *Case) NewRequestDataHandler() (RequestDataHandler, error)

func (*Case) ParsedURL

func (c *Case) ParsedURL() *url.URL

func (*Case) ReadFileForData

func (c *Case) ReadFileForData(fileName string) (io.Reader, error)

Open a data file for reading. TODO: sandbox the dir!

func (*Case) SetDefaultURLBase

func (c *Case) SetDefaultURLBase(s string)

func (*Case) SetDone

func (c *Case) SetDone()

func (*Case) SetPrior

func (c *Case) SetPrior(p *Case)

func (*Case) SetResponseBody

func (c *Case) SetResponseBody(body io.ReadSeeker)

func (*Case) SetResponseHeader

func (c *Case) SetResponseHeader(h http.Header)

func (*Case) SetSuiteFileName

func (c *Case) SetSuiteFileName(fileName string)

func (*Case) SetTest

func (c *Case) SetTest(t *testing.T, parent *testing.T)

func (*Case) SetXFailure

func (c *Case) SetXFailure()

type EnvironReplacer

type EnvironReplacer struct {
	BaseStringReplacer
}

func (*EnvironReplacer) Replace

func (e *EnvironReplacer) Replace(c *Case, in string) (string, error)

func (*EnvironReplacer) Resolve

func (e *EnvironReplacer) Resolve(prior *Case, argValue, cast string) (string, error)

type HeaderResponseHandler

type HeaderResponseHandler struct {
	BaseResponseHandler
}

func (*HeaderResponseHandler) Assert

func (h *HeaderResponseHandler) Assert(c *Case)

func (*HeaderResponseHandler) Replacer

func (h *HeaderResponseHandler) Replacer(c *Case, v string) string

type HeadersReplacer

type HeadersReplacer struct {
	BaseStringReplacer
}

func (*HeadersReplacer) Replace

func (h *HeadersReplacer) Replace(c *Case, in string) (string, error)

func (*HeadersReplacer) Resolve

func (h *HeadersReplacer) Resolve(prior *Case, argValue, cast string) (string, error)

type JSONHandler

type JSONHandler struct {
	BaseStringReplacer
	BaseResponseHandler
}

func (*JSONHandler) Accepts

func (*JSONHandler) Accepts(c *Case) bool

func (*JSONHandler) Assert

func (j *JSONHandler) Assert(c *Case)

func (*JSONHandler) GetBody

func (j *JSONHandler) GetBody(c *Case) (io.Reader, error)

func (*JSONHandler) ProcessOnePath

func (j *JSONHandler) ProcessOnePath(c *Case, rawJSON interface{}, path string, v interface{}) error

func (*JSONHandler) ReadJSONFromDisk

func (j *JSONHandler) ReadJSONFromDisk(c *Case, stringData string) (string, error)

ReadJSONFromDisk, selecting a json path from it, if there is a : in the filename.

func (*JSONHandler) ReadJSONReponse

func (j *JSONHandler) ReadJSONReponse(c *Case) (interface{}, error)

func (*JSONHandler) Replace

func (j *JSONHandler) Replace(c *Case, in string) (string, error)

func (*JSONHandler) Resolve

func (j *JSONHandler) Resolve(prior *Case, argValue, cast string) (string, error)

type LastURLReplacer

type LastURLReplacer struct {
	BaseStringReplacer
}

func (*LastURLReplacer) Replace

func (n *LastURLReplacer) Replace(c *Case, in string) (string, error)

type LocationReplacer

type LocationReplacer struct {
	BaseStringReplacer
}

func (*LocationReplacer) Replace

func (l *LocationReplacer) Replace(c *Case, in string) (string, error)

func (*LocationReplacer) Resolve

func (l *LocationReplacer) Resolve(prior *Case, argValue, cast string) (string, error)

type MultiSuite

type MultiSuite struct {
	Suites []*Suite
}

func NewMultiSuiteFromYAMLFiles

func NewMultiSuiteFromYAMLFiles(t *testing.T, defaultURLBase string, fileNames ...string) (*MultiSuite, error)

func (*MultiSuite) Execute

func (m *MultiSuite) Execute(t *testing.T)

Execute a MultiSuite in parallel.

type NetlocReplacer

type NetlocReplacer struct {
	BaseStringReplacer
}

func (*NetlocReplacer) Replace

func (n *NetlocReplacer) Replace(c *Case, in string) (string, error)

type NilDataHandler

type NilDataHandler struct{}

func (*NilDataHandler) GetBody

func (n *NilDataHandler) GetBody(c *Case) (io.Reader, error)

type Poll

type Poll struct {
	Count *int     `yaml:"count,omitempty"`
	Delay *float32 `yaml:"delay,omitempy"`
}

type RequestDataHandler

type RequestDataHandler interface {
	GetBody(c *Case) (io.Reader, error)
}

type Requester

type Requester interface {
	Do(*Case)
	ExecuteOne(*Case)
}

type ResponseHandler

type ResponseHandler interface {
	Accepts(*Case) bool
	Assert(*Case)
}

type SchemeReplacer

type SchemeReplacer struct {
	BaseStringReplacer
}

func (*SchemeReplacer) Replace

func (s *SchemeReplacer) Replace(c *Case, in string) (string, error)

type StringReplacer

type StringReplacer interface {
	Replace(*Case, string) (string, error)
	Resolve(*Case, string, string) (string, error)
	GetRegExp() *regexp.Regexp
}

type StringResponseHandler

type StringResponseHandler struct {
	BaseResponseHandler
}

func (*StringResponseHandler) Assert

func (s *StringResponseHandler) Assert(c *Case)

type Suite

type Suite struct {
	Name   string
	Client Requester
	File   string
	Cases  []*Case
}

func NewSuiteFromYAMLFile

func NewSuiteFromYAMLFile(t *testing.T, defaultURLBase, fileName string) (*Suite, error)

func (*Suite) Execute

func (s *Suite) Execute(t *testing.T)

Execute a single Suite, in series.

type SuiteYAML

type SuiteYAML struct {
	Defaults Case
	Fixtures interface{}
	Tests    []Case
}

type TextDataHandler

type TextDataHandler struct{}

func (*TextDataHandler) GetBody

func (t *TextDataHandler) GetBody(c *Case) (io.Reader, error)

type URLReplacer

type URLReplacer struct {
	BaseStringReplacer
}

func (*URLReplacer) Replace

func (u *URLReplacer) Replace(c *Case, in string) (string, error)

func (*URLReplacer) Resolve

func (u *URLReplacer) Resolve(prior *Case, argValue, cast string) (string, error)

Jump to

Keyboard shortcuts

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