Documentation
¶
Overview ¶
Package testkit helps Go projects write Tuile-backed integration and browser smoke tests.
Start an in-process Tuile server, create sessions, assert on headless screen output, and optionally drive the /view browser terminal with chromedp (requires Chrome/Chromium).
Example:
func TestSmoke(t *testing.T) {
srv := testkit.NewServer(t)
sess := srv.NewSession(t, t.TempDir())
sess.Input(t, "printf hello\\n")
sess.WaitContains(t, "hello")
}
Downstream projects: add github.com/newtosh/tuile to go.mod (use replace for local dev). Run integration tests in CI with headless Chrome; pre-commit is not recommended for browser tests.
Index ¶
- Constants
- func BrowserContext(t *testing.T) (context.Context, context.CancelFunc)
- func DefaultListenHostPort() string
- func FormatViewURL(baseURL, sessionID, token string) string
- func PortOpen(hostport string) bool
- func ViewIndexURL(baseURL string) string
- type Server
- type Session
- func (sess *Session) AssertTerminalContains(t *testing.T, marker string)
- func (sess *Session) EmitMarker(t *testing.T, workspace, marker string)
- func (sess *Session) GetWithToken(t *testing.T, path string) *http.Response
- func (sess *Session) HumanResize(t *testing.T, cols, rows int)
- func (sess *Session) Input(t *testing.T, input string)
- func (sess *Session) PlainScreen(t *testing.T, tail int) string
- func (sess *Session) PostInputRaw(t *testing.T, body []byte)
- func (sess *Session) Resize(t *testing.T, cols, rows int)
- func (sess *Session) ScreenGrid(t *testing.T) (cols, rows int)
- func (sess *Session) ServerURL() string
- func (sess *Session) SessionID() string
- func (sess *Session) Takeover(t *testing.T)
- func (sess *Session) TerminalText(t *testing.T) string
- func (sess *Session) ViewURL() string
- func (sess *Session) WaitContains(t *testing.T, marker string)
- func (sess *Session) WaitContainsTimeout(t *testing.T, marker string, timeout time.Duration)
- func (sess *Session) WaitForShell(t *testing.T)
Constants ¶
const DefaultBaseURL = "http://127.0.0.1:7710"
DefaultBaseURL is the standard loopback address for `tuile serve`.
Variables ¶
This section is empty.
Functions ¶
func BrowserContext ¶
BrowserContext returns a chromedp context with timeout; caller must cancel.
func DefaultListenHostPort ¶ added in v0.2.0
func DefaultListenHostPort() string
DefaultListenHostPort returns the host:port portion of DefaultBaseURL.
func FormatViewURL ¶ added in v0.2.0
FormatViewURL builds a browser observe link for a session.
func ViewIndexURL ¶ added in v0.2.0
ViewIndexURL returns the Tuile session list / viewer root.
Types ¶
type Server ¶
type Server struct {
URL string
Boot auth.BootstrapSecret
// contains filtered or unexported fields
}
Server is an in-process Tuile HTTP server for tests.
func ConnectURL ¶ added in v0.2.0
ConnectURL attaches to an already-running Tuile without starting serve.
func EnsureServe ¶ added in v0.2.0
EnsureServe returns a Server connected to baseURL (TUILE_URL or DefaultBaseURL). If nothing is listening, it starts `tuile serve` on that address and registers cleanup. Bootstrap secret: TUILE_BOOTSTRAP_SECRET, then bootstrap_secret from tuile.toml (cwd/parents).
func (*Server) DeleteSession ¶ added in v0.1.2
DeleteSession closes a session via DELETE /v1/sessions/{id}.
type Session ¶
Session is one Tuile PTY session created via the HTTP API.
func (*Session) AssertTerminalContains ¶
AssertTerminalContains polls the viewer until marker appears or times out.
func (*Session) EmitMarker ¶
EmitMarker writes marker to a file in workspace and cats it. Unlike echo/printf, the shell echo line does not contain marker text, so WaitContains cannot match prematurely on typed command text.
func (*Session) GetWithToken ¶
GetWithToken performs GET with the session token (for isolation tests).
func (*Session) HumanResize ¶
HumanResize sets PTY size while human controls the session.
func (*Session) PlainScreen ¶
PlainScreen returns the plain-text tail of the session screen.
func (*Session) PostInputRaw ¶
PostInputRaw sends a pre-marshaled JSON body to /input (for advanced tests).
func (*Session) ScreenGrid ¶
ScreenGrid returns cols and rows from the JSON screen endpoint.
func (*Session) TerminalText ¶
TerminalText opens the session view URL, waits for xterm, and returns visible terminal text. Skips the test when Chrome/chromedp is unavailable.
func (*Session) WaitContains ¶
WaitContains blocks until the session screen tail contains marker (POST /wait).
func (*Session) WaitContainsTimeout ¶
WaitContainsTimeout is WaitContains with a custom timeout.
func (*Session) WaitForShell ¶
WaitForShell blocks until the session PTY shows an interactive shell prompt.