testing

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MPL-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testing is a framework package to be used inside services unit tests providing an API to build specific services unit tests.

Index

Constants

View Source
const (
	JSONContentType           = "application/json"
	FormUrlencodedContentType = "application/x-www-form-urlencoded"
	FormDataContentType       = "multipart/form-data"
)

Variables

This section is empty.

Functions

func MockAny

func MockAny() gomock.Matcher

MockAny gives access to a gomock.Matcher object which can replace any kind of argument. This API can be called without a Testing object.

func MockController

func MockController(t *testing.T) *gomock.Controller

MockController gives access to a gomock.Controller object that enables creating a service mock to be used inside tests. This API can be called without a Testing object.

Types

type Options

type Options struct {
	// Handler is the service main HTTP handler to be used inside a test.
	Handler fasthttp.RequestHandler

	// MockedFeatures is an array of features that will be mocked during the
	// test.
	MockedFeatures []interface{}

	// FeatureOptions is the mechanism that a test can pass specific features
	// options to be used by it.
	FeatureOptions map[string]interface{}
}

Options gathers all available options that can be swapped inside a unit test. It is important that the Setup/Teardown API is used correctly to avoid receiving unexpected behavior.

type RequestOptions

type RequestOptions struct {
	Path        string
	Headers     map[string]string
	ContentType string
	Body        interface{}
	QueryParams map[string]string
}

type Response

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

func (*Response) Body

func (r *Response) Body() []byte

func (*Response) StatusCode

func (r *Response) StatusCode() int

type Testing

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

func New

func New(t *testing.T, options ...*Options) *Testing

New creates a new Testing object, to help building service unit tests. It can be used inside a Test function or test subset providing access to assertions and APIs to build specific required types when calling services handlers.

func (*Testing) Assert

func (t *Testing) Assert() *assert.Assertions

Assert gives access to an assertion object, providing an API to compare values between variables or objects.

func (*Testing) Delete

func (t *Testing) Delete(opts *RequestOptions) (*Response, error)

Delete makes a DELETE request to a service's endpoint.

func (*Testing) Get

func (t *Testing) Get(opts *RequestOptions) (*Response, error)

Get makes a GET request to a service's endpoint.

func (*Testing) HttpHandler

func (t *Testing) HttpHandler() fasthttp.RequestHandler

HttpHandler gives access to the service HTTP request handler.

func (*Testing) MockAny

func (t *Testing) MockAny() gomock.Matcher

func (*Testing) MockController

func (t *Testing) MockController() *gomock.Controller

MockController gives access to a gomock.Controller object that enables creating a service mock to be used inside tests.

func (*Testing) Options

func (t *Testing) Options() *Options

Options gives access to the internal Testing layer options.

func (*Testing) Patch

func (t *Testing) Patch(opts *RequestOptions) (*Response, error)

Patch makes a PATCH request to a service's endpoint.

func (*Testing) Post

func (t *Testing) Post(opts *RequestOptions) (*Response, error)

Post makes a POST request to a service's endpoint.

func (*Testing) Put

func (t *Testing) Put(opts *RequestOptions) (*Response, error)

Put makes a PUT request to a service's endpoint.

func (*Testing) SkipCICD

func (t *Testing) SkipCICD()

SkipCICD skips the test if the CICD_TEST environment variable is set to true.

func (*Testing) T

func (t *Testing) T() *testing.T

T gives access to the internal golang testing.T object.

Jump to

Keyboard shortcuts

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