apitest

package
v0.0.0-...-99a89de Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package apitest contains supporting code for running app layer tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CmpAppErrors

func CmpAppErrors(got any, exp any) string

CmpAppErrors compares two encore error values. If they are not equal, the reason is returned.

func Token

func Token(db *dbtest.Database, ath *auth.Auth, email string) string

Token generates an authenticated token for a user.

Types

type AuthHandler

type AuthHandler func(ctx context.Context, ap *AuthParams) (eauth.UID, *auth.Claims, error)

AuthHandler represents a function that can perform authentication.

type AuthParams

type AuthParams struct {
	Authorization string `header:"Authorization"`
}

AuthParams provides access to the authorization header.

type KeyStore

type KeyStore struct{}

KeyStore represents a mock keystore with a hardcoded key.

func (*KeyStore) PrivateKey

func (ks *KeyStore) PrivateKey(kid string) (string, error)

PrivateKey implements the auth interface.

func (*KeyStore) PublicKey

func (ks *KeyStore) PublicKey(kid string) (string, error)

PublicKey implements the auth interface.

type SeedData

type SeedData struct {
	Users  []User
	Admins []User
}

SeedData represents users for app tests.

type Table

type Table struct {
	Name    string
	Token   string
	ExpResp any
	ExcFunc func(ctx context.Context) any
	CmpFunc func(got any, exp any) string
}

Table represent fields needed for running an app test.

type Test

type Test struct {
	DB   *dbtest.Database
	Auth *auth.Auth
	// contains filtered or unexported fields
}

Test contains functions for executing an api test.

func New

func New(db *dbtest.Database, ath *auth.Auth, handler AuthHandler) *Test

New constructs a Test value for running api tests.

func (*Test) Run

func (at *Test) Run(t *testing.T, table []Table, testName string)

Run performs the actual test logic based on the table data.

type User

type User struct {
	userbus.User
	Products []productbus.Product
	Homes    []homebus.Home
	Token    string
}

User extends the dbtest user for app test support.

Jump to

Keyboard shortcuts

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