testutils

package
v0.0.0-...-520f1c6 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Now = func() time.Time {
	return time.Date(2020, 01, 01, 12, 00, 00, 01234567, time.UTC)
}

Now mocks the current time

Functions

func FormatJSON

func FormatJSON(b []byte) (string, error)

FormatJSON formats json string to be added to golden file

func LoadFixtures

func LoadFixtures(t *testing.T, dir string)

LoadFixtures is called before executing each test, it clears db and loads data from fixtures so that each test is executed on new db

func NowAfterDuration

func NowAfterDuration(dur time.Duration) func() time.Time

NowAfterDuration returns a time one second after adding the duration in Now

Types

type TestConfig

type TestConfig struct {
	*app.APIConfig
	// contains filtered or unexported fields
}

TestConfig defines configurations required for running tests APIConfig contains the db object, logger and github oauth conf fixturePath is the path to fixture directory which contains test data configPath is the path to test config file err will have error if occured during initialising the test db connection

func Config

func Config() *TestConfig

Config creates the test configuration once and returns the same every time the function is called

func Setup

func Setup(t *testing.T) *TestConfig

Setup when called first time will connect to test db, run migration to create tables and return TestConfig configurations. After that each time it is called it just retuns TestConfig configurations

func (*TestConfig) AddScopesForUser

func (tc *TestConfig) AddScopesForUser(userID uint, scopes []string) error

AddScopesForUser adds scopes for passed User ID

func (*TestConfig) AgentWithScopes

func (tc *TestConfig) AgentWithScopes(name string, scopes ...string) (*model.User, string, error)

AgentWithScopes returns JWT for user with required scopes

func (*TestConfig) Error

func (tc *TestConfig) Error() error

Error returns error if occured during initialising connection to test db

func (*TestConfig) FixturePath

func (tc *TestConfig) FixturePath() string

FixturePath return the directory path to fixtures

func (*TestConfig) IsValid

func (tc *TestConfig) IsValid() bool

IsValid checks if connection to test db is valid or not

func (*TestConfig) Path

func (tc *TestConfig) Path() string

Path return the file path to test config

func (*TestConfig) RefreshTokenForUser

func (tc *TestConfig) RefreshTokenForUser(name, email string) (*model.User, string, error)

RefreshTokenForUser returns refresh JWT for user with refresh:token scope User will have same github login and github name in db

func (*TestConfig) UserWithScopes

func (tc *TestConfig) UserWithScopes(name, email string, scopes ...string) (*model.User, string, error)

UserWithScopes returns JWT for user with required scopes User will have same github login and github name in db

Jump to

Keyboard shortcuts

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