testutils

package
v0.0.0-...-8ad1ab3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualStructs

func EqualStructs(a interface{}, b interface{}) bool

func ExtractResponse

func ExtractResponse[T any](w *httptest.ResponseRecorder) (*T, int, error)

func GetDefaultBusiness

func GetDefaultBusiness(user *User) *Business

func GetDefaultItem

func GetDefaultItem(business *Business) *ItemDefinition

func GetDefaultOwnedItem

func GetDefaultOwnedItem(itemDefinition *ItemDefinition, card *VirtualCard) *OwnedItem

func GetDefaultUser

func GetDefaultUser() *User

func GetTestBusiness

func GetTestBusiness(db GormDB, user *User) *Business

func GetTestDatabase

func GetTestDatabase() *GormDBImpl

Creates a new database connection from environment variables. Wipes the database. TEST_DATABASE_URL - database URL, ex. 'postgres://postgres@localhost/stampwallet' TEST_DATABASE_NAME - database name, ex. 'stampwallet' NOTE NEVER CALL THIS FROM PARALLEL TESTS. MAKE SURE go test HAD `-p 1` PARAMETER otherwise existing db connections might unexpectedly close. TODO move connection closing to tests

func GetTestFileMetadata

func GetTestFileMetadata(db GormDB, user *User) *FileMetadata

func GetTestItemDefinition

func GetTestItemDefinition(db GormDB, business *Business, metadata FileMetadata) *ItemDefinition

func GetTestItemDefinitionWithPrice

func GetTestItemDefinitionWithPrice(db GormDB, business *Business, metadata FileMetadata, price uint) *ItemDefinition

func GetTestLocalCard

func GetTestLocalCard(db GormDB, user *User) *LocalCard

func GetTestMenuImage

func GetTestMenuImage(db GormDB, business *Business) *MenuImage

func GetTestOwnedItem

func GetTestOwnedItem(db GormDB, itemDefinition *ItemDefinition, card *VirtualCard) *OwnedItem

func GetTestOwnedItemUsed

func GetTestOwnedItemUsed(db GormDB, itemDefinition *ItemDefinition, card *VirtualCard) *OwnedItem

func GetTestSessionToken

func GetTestSessionToken(db GormDB, user *User, expires time.Time) (*Token, string)

func GetTestToken

func GetTestToken(db GormDB, user *User) (*Token, string)

func GetTestTransaction

func GetTestTransaction(db GormDB, virtualCard *VirtualCard, items []OwnedItem) (*Transaction, []TransactionDetail)

func GetTestUser

func GetTestUser(db GormDB) *User

func GetTestVirtualCard

func GetTestVirtualCard(db GormDB, user *User, business *Business) *VirtualCard

func GetTestVirtualCardWithPoints

func GetTestVirtualCardWithPoints(db GormDB, user *User, business *Business, points uint) *VirtualCard

func MatchEntities

func MatchEntities(matcher interface{}, Obj interface{}) bool

Recursively compares matcher with obj. Only keys present in matcher are compared Mostly broken. Should only be used in tests. Note: for exact equality reflect.DeepEqual should be used instead

func Ptr

func Ptr[T Copyable](s T) *T

func RecreateDatabase

func RecreateDatabase(db GormDB, databaseName string) error

Wipes the database

func ReturnArg

func ReturnArg(arg interface{}) interface{}

func Save

func Save(db GormDB, item any)

func TestFileReader

func TestFileReader(filename string) (io.Reader, string)

func TestFileReaderWithoutMultipart

func TestFileReaderWithoutMultipart(filename string) io.Reader

func TimeJustAroundNow

func TimeJustAroundNow(x time.Time) bool

Types

type Anything

type Anything struct{}

func (Anything) Match

func (Anything) Match(v driver.Value) bool

type Copyable

type Copyable interface {
	int32 | uint64 | uint | string | bool | time.Time | database.GPSCoordinates
}

type StructMatcher

type StructMatcher struct {
	Obj interface{}
}

func (StructMatcher) Matches

func (matcher StructMatcher) Matches(x interface{}) bool

func (StructMatcher) String

func (StructMatcher) String() string

type TestContextBuilder

type TestContextBuilder struct{ Context *gin.Context }

func TestContextCopy

func TestContextCopy(c *gin.Context) *TestContextBuilder

func (*TestContextBuilder) AddQueryParam

func (tc *TestContextBuilder) AddQueryParam(paramName string, paramValue string) *TestContextBuilder

func (*TestContextBuilder) AttachTestJpeg

func (tc *TestContextBuilder) AttachTestJpeg() *TestContextBuilder

func (*TestContextBuilder) AttachTestPng

func (tc *TestContextBuilder) AttachTestPng() *TestContextBuilder

func (*TestContextBuilder) SetBody

func (tc *TestContextBuilder) SetBody(jsonBytes []byte) *TestContextBuilder

func (*TestContextBuilder) SetDefaultToken

func (tc *TestContextBuilder) SetDefaultToken() *TestContextBuilder

func (*TestContextBuilder) SetDefaultUrl

func (tc *TestContextBuilder) SetDefaultUrl() *TestContextBuilder

func (*TestContextBuilder) SetDefaultUser

func (tc *TestContextBuilder) SetDefaultUser() *TestContextBuilder

func (*TestContextBuilder) SetEndpoint

func (tc *TestContextBuilder) SetEndpoint(endpointPath string) *TestContextBuilder

func (*TestContextBuilder) SetHeader

func (tc *TestContextBuilder) SetHeader(headerKey string, headerValue string) *TestContextBuilder

func (*TestContextBuilder) SetMethod

func (tc *TestContextBuilder) SetMethod(method string) *TestContextBuilder

func (*TestContextBuilder) SetParam

func (tc *TestContextBuilder) SetParam(key string, value string) *TestContextBuilder

func (*TestContextBuilder) SetTestFile

func (tc *TestContextBuilder) SetTestFile(filename string) *TestContextBuilder

Overwrites request body Lifted from https://github.com/gin-gonic/gin/blob/master/context_test.go > TestContextFormFile

func (*TestContextBuilder) SetToken

func (tc *TestContextBuilder) SetToken(token string) *TestContextBuilder

func (*TestContextBuilder) SetUrl

func (tc *TestContextBuilder) SetUrl(argUrl *url.URL) *TestContextBuilder

func (*TestContextBuilder) SetUser

type TimeGreaterThanNow

type TimeGreaterThanNow struct {
	Time time.Time
}

func (TimeGreaterThanNow) Matches

func (matcher TimeGreaterThanNow) Matches(x interface{}) bool

func (TimeGreaterThanNow) String

func (TimeGreaterThanNow) String() string

type TimeJustBeforeNow

type TimeJustBeforeNow struct {
}

func (TimeJustBeforeNow) Matches

func (matcher TimeJustBeforeNow) Matches(x interface{}) bool

func (TimeJustBeforeNow) String

func (TimeJustBeforeNow) String() string

Jump to

Keyboard shortcuts

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