uitest

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package uitest provides a mock implementation of gas.UIProvider for use in tests. The mock records all calls and allows configuring per-method behavior via function fields.

mock := &uitest.MockUI{}
mock.RenderFn = func(w http.ResponseWriter, name string, data any) error {
    w.Write([]byte("<h1>Hello</h1>"))
    return nil
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call struct {
	Method string
	Args   []any
}

Call records a single method invocation on the mock.

type MockUI

type MockUI struct {
	RenderFn           func(w http.ResponseWriter, name string, data any) error
	RenderFragmentFn   func(w http.ResponseWriter, name string, data any) error
	RenderWithStatusFn func(w http.ResponseWriter, status int, name string, data any) error
	RegisterFuncsFn    func(funcs template.FuncMap)
	Calls              []Call
	// contains filtered or unexported fields
}

MockUI is a configurable mock of gas.UIProvider. Each method delegates to its corresponding Fn field if set, otherwise returns the zero value without writing to the ResponseWriter. All calls are recorded in the Calls slice for assertions.

func (*MockUI) CallCount

func (m *MockUI) CallCount(method string) int

CallCount returns the number of times the given method was called.

func (*MockUI) RegisterFuncs

func (m *MockUI) RegisterFuncs(funcs template.FuncMap)

RegisterFuncs records the call and delegates to RegisterFuncsFn if set.

func (*MockUI) Render

func (m *MockUI) Render(w http.ResponseWriter, name string, data any) error

Render records the call and delegates to RenderFn if set.

func (*MockUI) RenderFragment

func (m *MockUI) RenderFragment(w http.ResponseWriter, name string, data any) error

RenderFragment records the call and delegates to RenderFragmentFn if set.

func (*MockUI) RenderWithStatus

func (m *MockUI) RenderWithStatus(w http.ResponseWriter, status int, name string, data any) error

RenderWithStatus records the call and delegates to RenderWithStatusFn if set.

func (*MockUI) Reset

func (m *MockUI) Reset()

Reset clears all recorded calls.

Jump to

Keyboard shortcuts

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