Documentation
¶
Overview ¶
Package testkit - the part of the module SDK a module's tests use, as a module from its own repository can:
- rendering: the engine's templates with the module's (UseEngineRoot, RenderPageContent, RenderPlacement…), the modules switched on and off (WithModules), a theme or the embedded assets (UseTheme, UseModuleAssets);
- handler tests: fakes of the core's services (Auth, Users, Nodes), a session with a CSRF token (Session, PostForm), the module's mux (ModuleMux), deleting content (NodeDeleter), the actions recorded for the action log (CaptureActions);
- the database (built with the dbintegration tag only, run on the servers KOSATKA_TEST_MYSQL_DSN and KOSATKA_TEST_POSTGRES_DSN name - the engine's scripts/test_db.sh starts both; without them a test is skipped): every set's schema installed (SchemaDB) and the core's repositories and services on it (Deps).
Index ¶
- func CaptureActions(t *testing.T) *[]modulekit.ActionEvent
- func EngineRoot() string
- func FileStorageConfig(publicStorage string, sections map[string]any) modulekit.FileStorageConfig
- func Logger() *slog.Logger
- func ModuleMux(mux *http.ServeMux, module string, notFound http.HandlerFunc) modulekit.Mux
- func NodeDeleter(nodes modulekit.NodesRepository, ...) modulekit.NodeDeleter
- func PageData() map[string]any
- func PostForm(path string, form url.Values, cookies []*http.Cookie) *http.Request
- func RegisterModules()
- func RenderNamed(t testing.TB, name string, data any, files ...string) string
- func RenderPageBlock(t testing.TB, page, block string, data any) string
- func RenderPageContent(t testing.TB, page string, data any) string
- func RenderPlacement(t testing.TB, p modulekit.BlockPlacement, pageData map[string]any) string
- func ResolveTemplate(path string) (string, error)
- func Session(t testing.TB) (*sessions.CookieStore, []*http.Cookie, string)
- func Templates() modulekit.TemplateService
- func UseEngineRoot(t testing.TB)
- func UseImageStyleFormats(t testing.TB, formats map[string]imagestyle.Format)
- func UseImageStyleVersions(t testing.TB, versions map[string]string)
- func UseModuleAssets(t testing.TB, assets map[string]fs.FS)
- func UseTheme(t testing.TB, themesDir, theme string)
- func WithModules(t testing.TB, states map[string]bool)
- type Auth
- func (a Auth) CanCreateNode(context.Context, modulekit.ContentType, *modulekit.User) bool
- func (a Auth) CanDeleteNode(context.Context, *modulekit.Node, *modulekit.User) bool
- func (a Auth) CanEditNode(context.Context, *modulekit.Node, *modulekit.User) bool
- func (a Auth) CanUseSiteInMaintenanceMode(context.Context, *modulekit.User) bool
- func (a Auth) CanViewNode(_ context.Context, n *modulekit.Node, _ *modulekit.User) bool
- func (a Auth) ContentVisitor(context.Context, *modulekit.User) (modulekit.ContentVisitor, error)
- func (a Auth) CreatableNodeTypes(context.Context, *modulekit.User) []modulekit.CreatableMaterialLink
- func (a Auth) GetUserID(*http.Request) (int, bool)
- func (a Auth) HasPermission(_ context.Context, _ *modulekit.User, perm string) bool
- type Nodes
- type Users
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureActions ¶
func CaptureActions(t *testing.T) *[]modulekit.ActionEvent
CaptureActions - the actions recorded for the action log during the test (modulekit.RecordAction, RecordNodeCreated…), in order; the other listeners are dropped until it ends.
func EngineRoot ¶
func EngineRoot() string
EngineRoot - the engine's source tree, whose templates (web/templates), themes and translations a module's rendering tests read: this package's directory two levels up - the engine's repository, or the engine's module in the module cache for a module from its own repository.
func FileStorageConfig ¶
func FileStorageConfig(publicStorage string, sections map[string]any) modulekit.FileStorageConfig
FileStorageConfig - the config a file storage's Public and Private get on a site whose public files are in publicStorage ("local", or the storage's name), with sections as the config file's files.<section> (e.g. {"s3": {"bucket": "site"}}); Decode reads the environment over them, as on a site.
func ModuleMux ¶
ModuleMux - the module's routes' mux on mux, as the site gives it: its routes answer notFound while the module is off.
func NodeDeleter ¶
func NodeDeleter(nodes modulekit.NodesRepository, deleteNode func(ctx context.Context, id int) error) modulekit.NodeDeleter
NodeDeleter - the core's deleting of content of a handler test: nodes finds an item, deleteNode deletes it (its files untouched).
func PageData ¶
PageData - a whole page's data with no blocks placed in its regions, for rendering a layout (RenderPageBlock with "layout.html"); more is added to it by the test.
func PostForm ¶
PostForm - a form POST to path (with the session's cookies; the form carries what the test gives, the CSRF token too if it wants it).
func RegisterModules ¶
func RegisterModules()
RegisterModules puts the engine's modules in the registry (a module from its own repository registers itself, imported by the test).
func RenderNamed ¶
RenderNamed - the template name defined in files (template paths, as the template service resolves them).
func RenderPageBlock ¶
RenderPageBlock - the block of a page template (a template file and what it parses with it: the layout, the partials, the modules' hooks), as rendering the page renders it; a failure fails the test.
func RenderPageContent ¶
RenderPageContent - the "content" block of a page template.
func RenderPlacement ¶
RenderPlacement - the region of p with that one block, as a page renders its regions: a plugin block through its module's template (block_<id>), its PluginConfig as placed. pageData - the rest of the page's data the block reads (nil - none).
func ResolveTemplate ¶
ResolveTemplate - where the template path resolves ("embed:…" for a module's embedded one).
func Session ¶
Session - a cookie store with a session holding a CSRF token: its cookies and the token, for a form a test posts.
func Templates ¶
func Templates() modulekit.TemplateService
Templates - the template service a controller of a handler test renders with (modulekit.BaseDeps.Templates): the site's, uncached.
func UseEngineRoot ¶
UseEngineRoot makes the engine's source tree the test's working directory, where the template service reads from, and the modules' files where a site finds them: an engine module's directory under the engine's, a module from its own repository's assets of its registration.
func UseImageStyleFormats ¶
func UseImageStyleFormats(t testing.TB, formats map[string]imagestyle.Format)
UseImageStyleFormats gives the image styles their output formats (as the image styles page sets them) for the test.
func UseImageStyleVersions ¶
UseImageStyleVersions gives the image styles their versions in the derivatives' URLs (?v=…, as the site sets them from the styles' settings) for the test.
func UseModuleAssets ¶
UseModuleAssets serves the modules' templates and static files from their assets (the binary's embedded files), as on a site, for the test.
Types ¶
type Auth ¶
Auth - the core's AuthService of a handler test: UserID is the signed-in user (0 - none), Allow answers the content permission checks (create, edit, delete), Permissions the site-wide ones; any other method panics (the embedded nil interface).
func (Auth) CanCreateNode ¶
CanCreateNode - Allow.
func (Auth) CanDeleteNode ¶
CanDeleteNode - Allow.
func (Auth) CanEditNode ¶
CanEditNode - Allow.
func (Auth) CanUseSiteInMaintenanceMode ¶
CanUseSiteInMaintenanceMode - no one.
func (Auth) CanViewNode ¶
CanViewNode - a published node, or any while Allow.
func (Auth) ContentVisitor ¶
ContentVisitor - nothing hidden: all the content is open.
func (Auth) CreatableNodeTypes ¶
func (a Auth) CreatableNodeTypes(context.Context, *modulekit.User) []modulekit.CreatableMaterialLink
CreatableNodeTypes - none.
type Nodes ¶
type Nodes struct {
modulekit.NodesRepository
Known map[int]*modulekit.Node
}
Nodes - the core's NodesRepository knowing the content by ID (Known); any other method panics.