cases

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidToken is the error returned when the token is invalid.
	ErrInvalidToken = errors.New("invalid token")
	// ErrMalformedJSON is the error returned when the JSON is malformed.
	ErrMalformedJSON = errors.New("malformed json")
)
View Source
var (
	// ErrEndOfLine is the error returned when the end of the line is reached.
	ErrEndOfLine = errors.New("end of line")
)

Functions

This section is empty.

Types

type Case

type Case struct {
	// Name is the name of the test case.
	Name string `json:"case_name"`
	// Arrange
	Database `json:"database"`
	// Input
	Request `json:"request"`
	// Output
	Response `json:"response"`
}

Case is a test case.

type CaseErr

type CaseErr struct {
	// Case is the test case.
	Case Case
	// Err is the error.
	Err error
}

CaseErr is a test case with an error.

type Database

type Database struct {
	// SetUp is the set of set up queries to run before the test case.
	SetUp []string `json:"set_up"`
	// TearDown is the set of tear down queries to run after the test case.
	TearDown []string `json:"tear_down"`
}

Database is a database to run the test case against.

type DbExecuter

type DbExecuter interface {
	// Exec executes queries on the database.
	Exec(queries ...string) (err error)
}

DbExecuter is an interface for executing queries on a database.

type DbExecuterMock

type DbExecuterMock struct {
	mock.Mock
}

DbExecuterMock is a mock of dbexecuter.

func NewDbExecuterMock

func NewDbExecuterMock() *DbExecuterMock

NewDbExecuterMock creates a new dbexecuter mock.

func (*DbExecuterMock) Exec

func (m *DbExecuterMock) Exec(queries ...string) (err error)

Exec mocks base method.

type DbExecuterMySQL

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

DbExecuterMySQL is a MySQL database executer.

func NewDbExecuterMySQL

func NewDbExecuterMySQL(db *sql.DB) *DbExecuterMySQL

NewDbExecuterMySQL creates a new MySQL database executer.

func (*DbExecuterMySQL) Exec

func (e *DbExecuterMySQL) Exec(queries ...string) (err error)

Exec executes queries on the database.

type Reader

type Reader interface {
	// Read reads the next test case.
	Read() (c Case, err error)
}

Reader is a reader of test cases.

type ReaderJSON

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

ReaderJSON is a reader of test cases in JSON format.

func NewReaderJSON

func NewReaderJSON(decoder *json.Decoder, ch chan CaseErr) *ReaderJSON

NewReaderJSON creates a new reader of test cases in JSON format.

func (*ReaderJSON) Read

func (r *ReaderJSON) Read() (c Case, err error)

Read reads the next test case.

func (*ReaderJSON) Stream

func (r *ReaderJSON) Stream()

Stream is a concurrent reader of test cases

type ReaderMock

type ReaderMock struct {
	mock.Mock
}

ReaderMock is a mock of Reader.

func NewReaderMock

func NewReaderMock() (m *ReaderMock)

NewReaderMock creates a new mock of Reader.

func (*ReaderMock) Read

func (m *ReaderMock) Read() (c Case, err error)

Read is a mock of Read.

type Reporter

type Reporter interface {
	// Report reports the result of the test case.
	Report(c *Case, w *http.Response) (err error)
}

Reporter is a reporter of test cases.

type ReporterDefault

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

ReporterDefault is the default reporter of test cases.

func NewReporterDefault

func NewReporterDefault(excludedHeaders []string) *ReporterDefault

NewReporterDefault creates a new default reporter.

func (*ReporterDefault) Report

func (r *ReporterDefault) Report(c *Case, w *http.Response) (err error)

type ReporterMock

type ReporterMock struct {
	mock.Mock
}

ReporterMock is a mock of reporter.

func NewReporterMock

func NewReporterMock() *ReporterMock

NewReporterMock creates a new reporter mock.

func (*ReporterMock) Report

func (m *ReporterMock) Report(c *Case, resp *http.Response) (err error)

Report mocks base method.

type Request

type Request struct {
	// Method is the HTTP method to use for the request.
	Method string `json:"method"`
	// Path is the path to use for the request.
	Path string `json:"path"`
	// Query is the set of query parameters to use for the request.
	Query map[string]string `json:"query"`
	// Body is the body to use for the request.
	Body any `json:"body"`
	// Header is the set of headers to use for the request.
	Header http.Header `json:"header"`
}

Request is a request to make for the test case.

type Requester

type Requester interface {
	// Do makes the request.
	Do(c *Case) (resp *http.Response, err error)
}

Requester is the interface for cases's requests

type RequesterDefault

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

RequesterDefault is the default requester.

func NewRequesterDefault

func NewRequesterDefault(serverAddr string, client *http.Client) *RequesterDefault

NewRequesterDefault creates a new default requester.

func (*RequesterDefault) Do

func (r *RequesterDefault) Do(c *Case) (resp *http.Response, err error)

Do makes the request.

type RequesterMock

type RequesterMock struct {
	mock.Mock
}

RequesterMock is a mock of requester.

func NewRequesterMock

func NewRequesterMock() *RequesterMock

NewRequesterMock creates a new requester mock.

func (*RequesterMock) Do

func (m *RequesterMock) Do(c *Case) (resp *http.Response, err error)

Do mocks base method.

type Response

type Response struct {
	// Code is the expected status code of the response.
	Code int `json:"code"`
	// Body is the expected body of the response.
	Body any `json:"body"`
	// Header is the expected set of headers of the response.
	Header http.Header `json:"header"`
}

Response is the expected response of the test case.

Jump to

Keyboard shortcuts

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