test

package
v0.28.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: AGPL-3.0, AGPL-3.0-only Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const EnvExternalHTTP = "http" // external http server like hCaptcha
View Source
const EnvMysql = "mysql"
View Source
const EnvRedis = "redis"
View Source
const TreeHoleAccessToken = "a_development_access_token"

Variables

This section is empty.

Functions

func GetGorm

func GetGorm(tb testing.TB) *gorm.DB

func GetQuery

func GetQuery(tb testing.TB) *query.Query

func GetRedis added in v0.23.7

func GetRedis(tb testing.TB) *redis.Client

func GetWebApp

func GetWebApp(tb testing.TB, m Mock) *fiber.App

func MockAuthRepo

func MockAuthRepo(m domain.AuthRepo) fx.Option

func MockAuthService

func MockAuthService(m domain.AuthService) fx.Option

func MockCache

func MockCache(mock cache.RedisCache) fx.Option

func MockCaptchaManager

func MockCaptchaManager(repo captcha.Manager) fx.Option

func MockCharacterRepo

func MockCharacterRepo(m domain.CharacterRepo) fx.Option

func MockEmptyCache

func MockEmptyCache() fx.Option

func MockEpisodeRepo

func MockEpisodeRepo(m domain.EpisodeRepo) fx.Option

func MockIndexRepo

func MockIndexRepo(repo domain.IndexRepo) fx.Option

func MockOAuthManager

func MockOAuthManager(m oauth.Manager) fx.Option

func MockPersonRepo

func MockPersonRepo(m domain.PersonRepo) fx.Option

func MockRateLimiter

func MockRateLimiter(repo rate.Manager) fx.Option

func MockRevisionRepo

func MockRevisionRepo(repo domain.RevisionRepo) fx.Option

func MockSessionManager

func MockSessionManager(repo session.Manager) fx.Option

func MockSubjectRepo

func MockSubjectRepo(m subject.Repo) fx.Option

func MockTimeLineRepo added in v0.28.0

func MockTimeLineRepo(m domain.TimeLineRepo) fx.Option

func MockUserRepo

func MockUserRepo(repo domain.UserRepo) fx.Option

func RequireEnv

func RequireEnv(tb testing.TB, envs ...string)

RequireEnv

func TestGet(t *testing.T) {
  RequireEnv(t, test.EnvRedis, test.EnvMysql)
  ...
}

func RunAndCleanup

func RunAndCleanup(tb testing.TB, f func())

RunAndCleanup will run a function immediately and add it to t.Cleanup.

Types

type Mock

type Mock struct {
	SubjectRepo    subject.Repo
	PersonRepo     domain.PersonRepo
	CharacterRepo  domain.CharacterRepo
	AuthRepo       domain.AuthRepo
	AuthService    domain.AuthService
	EpisodeRepo    domain.EpisodeRepo
	TopicRepo      domain.TopicRepo
	GroupRepo      domain.GroupRepo
	UserRepo       domain.UserRepo
	IndexRepo      domain.IndexRepo
	RevisionRepo   domain.RevisionRepo
	CollectionRepo domain.CollectionRepo
	TimeLineRepo   domain.TimeLineRepo
	CaptchaManager captcha.Manager
	SessionManager session.Manager
	Cache          cache.RedisCache
	RateLimiter    rate.Manager
	OAuthManager   oauth.Manager
	HTTPMock       *httpmock.MockTransport
	Dam            *dam.Dam
}

type PagedResponse

type PagedResponse struct {
	Data   json.RawMessage `json:"data"`
	Total  int64           `json:"total"`
	Limit  int             `json:"limit"`
	Offset int             `json:"offset"`
}

type Request

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

func New

func New(t *testing.T) *Request

func (*Request) Cookie

func (r *Request) Cookie(key, value string) *Request

func (*Request) Delete

func (r *Request) Delete(path string) *Request

func (*Request) Execute

func (r *Request) Execute(app *fiber.App, msTimeout ...int) *Response

func (*Request) Form

func (r *Request) Form(key, value string) *Request

func (*Request) Get

func (r *Request) Get(path string) *Request

func (*Request) Header

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

func (*Request) JSON

func (r *Request) JSON(v any) *Request

func (*Request) Patch

func (r *Request) Patch(path string) *Request

func (*Request) Post

func (r *Request) Post(path string) *Request

func (*Request) Put

func (r *Request) Put(path string) *Request

func (*Request) Query

func (r *Request) Query(key, value string) *Request

func (*Request) StdRequest

func (r *Request) StdRequest() *http.Request

type Response

type Response struct {
	Header http.Header
	Body   []byte

	StatusCode int
	// contains filtered or unexported fields
}

func (*Response) BodyString

func (r *Response) BodyString() string

func (*Response) Cookies

func (r *Response) Cookies() []*http.Cookie

func (*Response) ExpectCode

func (r *Response) ExpectCode(t int) *Response

func (*Response) JSON

func (r *Response) JSON(v any) *Response

Jump to

Keyboard shortcuts

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