test_utils

package
v0.0.0-...-8122643 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExternalConfigPath = ""
View Source
var Phone = ""
View Source
var SqliteFolder string = ""
View Source
var Testing = ""

Functions

func AssetsFilePath

func AssetsFilePath(testDir string, fileName string) string

func BBGinEngine

func BBGinEngine(t *testing.T, server bare_bones_server.Server) *gin.Engine

func CheckDuplicateKeyError

func CheckDuplicateKeyError(provider string, result *gorm.DB) (bool, error)

func CheckGenericError

func CheckGenericError(t *testing.T, err error, expectedCode string, expectedMessage ...string)

func CheckResponse

func CheckResponse(t *testing.T, resp *HttpResponse, expected *Expected)

func CreateDatabase

func CreateDatabase(t *testing.T, dbConfig *PostgresDbConfig, dbName string)

func CreateDbModel

func CreateDbModel(t *testing.T, app app_context.Context, models ...interface{})

func CreateDbModels

func CreateDbModels(t *testing.T, app app_context.Context, models []interface{})

func DbCreator

func DbCreator(provider string, db *gorm.DB, dbName string) error

func DbDsnBuilder

func DbDsnBuilder(t *testing.T, config *db.DBConfig) (string, error)

func DbGormOpener

func DbGormOpener(provider string, dsn string) (gorm.Dialector, error)

func DefaultAppBuilder

func DefaultAppBuilder(t *testing.T, buildConfig *app_context.BuildConfig) app_context.Context

func DefaultAppInitializer

func DefaultAppInitializer(t *testing.T, app app_context.Context, configFile string, args []string, configType ...string) error

func DropDatabase

func DropDatabase(t *testing.T, dbConfig *PostgresDbConfig, dbName string)

func DumpError

func DumpError(t *testing.T, err error, message ...string)

func DumpObject

func DumpObject(t *testing.T, obj interface{}, message ...string)

func ExternalConfigFileExists

func ExternalConfigFileExists(path string) bool

func ExternalConfigFilePath

func ExternalConfigFilePath(path string) string

func HttpDelete

func HttpDelete(t *testing.T, g *gin.Engine, path string, cmd interface{}, headers ...map[string]string) (*httptest.ResponseRecorder, int, string)

func HttpGet

func HttpGet(t *testing.T, g *gin.Engine, path string, cmd interface{}, headers ...map[string]string) (*httptest.ResponseRecorder, int, string)

func HttpHeadersSet

func HttpHeadersSet(req *http.Request, headers ...map[string]string)

func HttpPatch

func HttpPatch(t *testing.T, g *gin.Engine, path string, cmd interface{}, headers ...map[string]string) (*httptest.ResponseRecorder, int, string)

func HttpPost

func HttpPost(t *testing.T, g *gin.Engine, path string, cmd interface{}, headers ...map[string]string) (*httptest.ResponseRecorder, int, string)

func HttpPut

func HttpPut(t *testing.T, g *gin.Engine, path string, cmd interface{}, headers ...map[string]string) (*httptest.ResponseRecorder, int, string)

func HttpRequestBody

func HttpRequestBody(t *testing.T, g *gin.Engine, method string, path string, cmd interface{}, headers ...map[string]string) (*httptest.ResponseRecorder, int, string)

func HttpRequestQuery

func HttpRequestQuery(t *testing.T, g *gin.Engine, method string, path string, args interface{}, headers ...map[string]string) (*httptest.ResponseRecorder, int, string)

func HttpRequestSend

func HttpRequestSend(t *testing.T, g *gin.Engine, req *http.Request) (*httptest.ResponseRecorder, int, string)

func InitAppContext

func InitAppContext(t *testing.T, testDir string, dbModels []interface{}, config string, newDb ...bool) app_context.Context

func InitAppContextNoDb

func InitAppContextNoDb(t *testing.T, testDir string, config ...string) app_context.Context

func InitDbModels

func InitDbModels(t *testing.T, testDir string, dbModels []interface{}, config ...string)

func InitDefaultAppContextNoDb

func InitDefaultAppContextNoDb(t *testing.T, testDir string, config ...string) app_context.Context

func IsTesting

func IsTesting() bool

func MultitenancyOpContext

func MultitenancyOpContext(app app_context.Context, name string) multitenancy.TenancyContext

func NoError

func NoError(t *testing.T, ctx op_context.Context, err error)

func NoErrorApp

func NoErrorApp(t *testing.T, app app_context.Context, err error)

func ObjectEqual

func ObjectEqual(t *testing.T, left common.Object, right common.Object)

func PartitionedMonthMigrator

func PartitionedMonthMigrator(provider string, ctx logger.WithLogger, db *gorm.DB, models ...interface{}) error

func ResponseErrorCode

func ResponseErrorCode(t *testing.T, resp *HttpResponse) string

func RestApiTestClient

func RestApiTestClient(t *testing.T, g *gin.Engine, baseUrl string, userAgent ...string) *rest_api_client.RestApiClientBase

func SetAppHandlers

func SetAppHandlers(builder AppBuilder, initializer AppInitializer)

func SetTesting

func SetTesting(t *testing.T)

func SetupGormDB

func SetupGormDB(t *testing.T)

func SimpleOpContext

func SimpleOpContext(app app_context.Context, name string) op_context.Context

func SqliteDatabasesPath

func SqliteDatabasesPath() string

func SqliteDbPath

func SqliteDbPath(fileName string) string

func SqlitePath

func SqlitePath(config *db.DBConfig) string

func UserOpContext

func UserOpContext(app app_context.Context, name string, user auth.User, tenancy ...multitenancy.Tenancy) auth.UserContext

Types

type AppBuilder

type AppBuilder = func(t *testing.T, buildConfig *app_context.BuildConfig) app_context.Context

type AppInitializer

type AppInitializer = func(t *testing.T, app app_context.Context, configFile string, args []string, configType ...string) error

type Expected

type Expected struct {
	Error    string
	Message  string
	Details  string
	HttpCode int
}

type HttpClient

type HttpClient struct {
	BaseUrl      string
	AccessToken  string
	RefreshToken string
	CsrfToken    string

	Gin *gin.Engine

	AutoSms bool

	T *testing.T
}

func NewHttpClient

func NewHttpClient(t *testing.T, gin *gin.Engine, baseUrl ...string) *HttpClient

func PrepareHttpClient

func PrepareHttpClient(t *testing.T, gin *gin.Engine, baseUrl ...string) *HttpClient

func (*HttpClient) Delete

func (c *HttpClient) Delete(path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) Get

func (c *HttpClient) Get(path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) Login

func (c *HttpClient) Login(user string, password string, expectedErrorCode ...string)

func (*HttpClient) Logout

func (c *HttpClient) Logout()

func (*HttpClient) Patch

func (c *HttpClient) Patch(path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) Post

func (c *HttpClient) Post(path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) PostSigned

func (c *HttpClient) PostSigned(t *testing.T, signer *crypt_utils.RsaSigner, path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) Prepare

func (c *HttpClient) Prepare()

func (*HttpClient) Put

func (c *HttpClient) Put(t *testing.T, path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) RequestBody

func (c *HttpClient) RequestBody(method string, path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) RequestQuery

func (c *HttpClient) RequestQuery(method string, path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) RequestRefreshToken

func (c *HttpClient) RequestRefreshToken(expectedErrorCode ...string)

func (*HttpClient) SendSmsConfirmation

func (c *HttpClient) SendSmsConfirmation(resp *HttpResponse, code string, method string, path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) SendSmsConfirmationWithToken

func (c *HttpClient) SendSmsConfirmationWithToken(resp *HttpResponse, token string, code string, method string, path string, cmd interface{}, headers ...map[string]string) *HttpResponse

func (*HttpClient) Sleep

func (c *HttpClient) Sleep(seconds int, message string)

func (*HttpClient) UpdateCsrfToken

func (c *HttpClient) UpdateCsrfToken()

func (*HttpClient) UpdateTokens

func (c *HttpClient) UpdateTokens()

func (*HttpClient) Url

func (c *HttpClient) Url(path string) string

type HttpResponse

type HttpResponse struct {
	Object  *httptest.ResponseRecorder
	Code    int
	Message string
}

type PostgresDbConfig

type PostgresDbConfig struct {
	DbHost     string
	DbPort     uint16
	DbUser     string
	DbPassword string

	DbNameForLogin string
	DbName         string
}

func NewPostgresDbConfig

func NewPostgresDbConfig() *PostgresDbConfig

func (*PostgresDbConfig) Url

func (p *PostgresDbConfig) Url() string

type RestApiTestResponse

type RestApiTestResponse struct {
	Raw *httptest.ResponseRecorder
	// contains filtered or unexported fields
}

func HttptestSendWithBody

func HttptestSendWithBody(t *testing.T, g *gin.Engine, method string, url string, cmd interface{}, headers ...map[string]string) *RestApiTestResponse

func HttptestSendWithQuery

func HttptestSendWithQuery(t *testing.T, g *gin.Engine, method string, url string, cmd interface{}, headers ...map[string]string) *RestApiTestResponse

func NewRestApiTestResponse

func NewRestApiTestResponse(raw *httptest.ResponseRecorder) (*RestApiTestResponse, error)

func (*RestApiTestResponse) Body

func (r *RestApiTestResponse) Body() []byte

func (*RestApiTestResponse) Code

func (r *RestApiTestResponse) Code() int

func (*RestApiTestResponse) Error

func (*RestApiTestResponse) Header

func (r *RestApiTestResponse) Header() http.Header

func (*RestApiTestResponse) Message

func (r *RestApiTestResponse) Message() string

func (*RestApiTestResponse) SetError

func (r *RestApiTestResponse) SetError(err generic_error.Error)

Jump to

Keyboard shortcuts

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