testutil

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthUserMiddleware added in v1.7.1

func AuthUserMiddleware(user *model.AccountDTO) gin.HandlerFunc

AuthUserMiddleware is a middleware that manually sets an user as authenticated in the context to be used in tests.

func FakeAdminLoggedInMiddlewware added in v1.7.1

func FakeAdminLoggedInMiddlewware(ctx *gin.Context)

FakeAdminLoggedInMiddlewware is a middleware that sets a fake admin account to context. Keep in mind that this users is not saved in database so any tests that use this middleware should not rely on database.

func FakeUserLoggedInMiddlewware added in v1.7.1

func FakeUserLoggedInMiddlewware(ctx *gin.Context)

FakeUserLoggedInMiddlewware is a middleware that sets a fake user account to context. Keep in mind that this users is not saved in database so any tests that use this middleware should not rely on database.

func GetTestConfigurationAndDependencies

func GetTestConfigurationAndDependencies(t *testing.T, ctx context.Context, logger *logrus.Logger) (*config.Config, *dependencies.Dependencies)

func GetValidBookmark

func GetValidBookmark() *model.BookmarkDTO

func NewGin

func NewGin() *gin.Engine

NewGin returns a new gin engine with test mode enabled.

func NewTestResponseFromBytes

func NewTestResponseFromBytes(b []byte) (*testResponse, error)

func NewTestResponseFromReader

func NewTestResponseFromReader(r io.Reader) (*testResponse, error)

func PerformRequest

func PerformRequest(handler http.Handler, method, path string, options ...Option) *httptest.ResponseRecorder

func PerformRequestWithRecorder

func PerformRequestWithRecorder(recorder *httptest.ResponseRecorder, r http.Handler, method, path string, options ...Option) *httptest.ResponseRecorder

Types

type Option

type Option = func(*http.Request)

func WithBody

func WithBody(body string) Option

func WithHeader

func WithHeader(name, value string) Option

Jump to

Keyboard shortcuts

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