golibtest

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: MIT Imports: 17 Imported by: 0

README

Golib Test

Note We are moving out from Gitlab. All packages are now migrated to github.com/golibs-starter/*. Please consider updating.

Testing stuff for Golang project.

Setup instruction

Base setup, see GoLib Instruction

Testing example

All examples in the testing directory of golib-sample

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnableWebTestUtil

func EnableWebTestUtil() fx.Option

func RequireFxApp

func RequireFxApp(options ...fx.Option) *fx.App

func RequireFxAppT

func RequireFxAppT(tb testing.TB, options ...fx.Option) *fx.App

func StartFxApp

func StartFxApp(options ...fx.Option) (*fx.App, error)

func StartFxAppT

func StartFxAppT(tb testing.TB, options ...fx.Option) (*fx.App, error)

func WaitUntil

func WaitUntil(cb func() bool, timeout time.Duration)

func WaitUntilT

func WaitUntilT(t testing.TB, cb func() bool, timeout time.Duration)

func WrapTestingLoggerOpt

func WrapTestingLoggerOpt(tb testing.TB) fx.Option

Types

type FxTestSuite

type FxTestSuite struct {
	suite.Suite
	// contains filtered or unexported fields
}

func (*FxTestSuite) Config

func (s *FxTestSuite) Config(opts ...TsConfig)

func (*FxTestSuite) Decorate

func (s *FxTestSuite) Decorate(decorators ...interface{})

func (*FxTestSuite) Invoke

func (s *FxTestSuite) Invoke(funcs ...interface{})

func (*FxTestSuite) Option

func (s *FxTestSuite) Option(opts ...fx.Option)

func (*FxTestSuite) Options

func (s *FxTestSuite) Options(opts []fx.Option)

func (*FxTestSuite) Populate

func (s *FxTestSuite) Populate(targets ...interface{})

func (*FxTestSuite) Profile

func (s *FxTestSuite) Profile(profiles ...string)

func (*FxTestSuite) ProfilePath

func (s *FxTestSuite) ProfilePath(paths ...string)

func (*FxTestSuite) Provide

func (s *FxTestSuite) Provide(constructors ...interface{})

func (*FxTestSuite) StartApp

func (s *FxTestSuite) StartApp()

type JsonAssured

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

JsonAssured ...

func NewJsonAssured

func NewJsonAssured(t *testing.T, message string) *JsonAssured

NewJsonAssured ...

func (*JsonAssured) Get

func (k *JsonAssured) Get(key string) interface{}

func (*JsonAssured) Has

func (k *JsonAssured) Has(key string, expected interface{}) *JsonAssured

Has ...

type RequestBuilder

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

RequestBuilder represent http request builder for test

func NewRequestBuilder

func NewRequestBuilder(restAssured *RestAssured) *RequestBuilder

NewRequestBuilder return a new instance of RequestBuilder

func (*RequestBuilder) BasicAuth

func (r *RequestBuilder) BasicAuth(username string, password string) *RequestBuilder

BasicAuth set basic auth credentials to request builder

func (*RequestBuilder) BearerToken

func (r *RequestBuilder) BearerToken(token string) *RequestBuilder

BearerToken set bearer token to request builder

func (*RequestBuilder) Body

func (r *RequestBuilder) Body(body string) *RequestBuilder

Body set request body

func (*RequestBuilder) Build

func (r *RequestBuilder) Build() *http.Request

Build create request from request builder

func (*RequestBuilder) Delete

func (r *RequestBuilder) Delete(url string) *RequestBuilder

Delete set delete method and url to request builder

func (*RequestBuilder) Get

func (r *RequestBuilder) Get(url string) *RequestBuilder

Get set get method and url to request builder

func (*RequestBuilder) Header

func (r *RequestBuilder) Header(key string, value string) *RequestBuilder

func (*RequestBuilder) Method

func (r *RequestBuilder) Method(method string) *RequestBuilder

Method set http method

func (*RequestBuilder) Patch

func (r *RequestBuilder) Patch(url string) *RequestBuilder

Patch set patch method and url to request builder

func (*RequestBuilder) Post

func (r *RequestBuilder) Post(url string) *RequestBuilder

Post set post method and url to request builder

func (*RequestBuilder) Put

func (r *RequestBuilder) Put(url string) *RequestBuilder

Put set post method and url to request builder

func (*RequestBuilder) Then

func (r *RequestBuilder) Then() *RestAssured

Then perform request

func (*RequestBuilder) URL

func (r *RequestBuilder) URL(url string) *RequestBuilder

URL set url method

type RestAssured

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

RestAssured represent rest assertion

func NewRestAssured

func NewRestAssured(t *testing.T) *RestAssured

NewRestAssured return a new instance of RestAssured

func NewRestAssuredSuite

func NewRestAssuredSuite(t suite.TestingSuite) *RestAssured

func (*RestAssured) Body

func (r *RestAssured) Body(key string, expected interface{}) *RestAssured

Body assert json body in response Read https://github.com/tidwall/gjson for more information about path syntax

func (*RestAssured) BodyCb

func (r *RestAssured) BodyCb(key string, expectedFn func(value interface{})) *RestAssured

func (*RestAssured) Header

func (r *RestAssured) Header(key string, expected interface{}) *RestAssured

Header assert http header

func (*RestAssured) Status

func (r *RestAssured) Status(expected int) *RestAssured

Status assert http status code

func (*RestAssured) When

func (r *RestAssured) When() *RequestBuilder

When create a new request builder

type TsConfig

type TsConfig func(ts *FxTestSuite)

func WithFxOption

func WithFxOption(opt fx.Option) TsConfig

func WithFxOptions

func WithFxOptions(opts ...fx.Option) TsConfig

Jump to

Keyboard shortcuts

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