writing-tests

Guides writing Go tests in clawker using fakes, moq mocks, command test tiers, and e2e harnesses.

54|6|Updated Jan 7, 2026
One-click install
npx skills add https://github.com/schmitthub/clawker --skill writing-tests-schmitthub
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: writing-tests
Source: https://github.com/schmitthub/clawker/tree/main/.agents/skills/writing-tests
Command: npx skills add https://github.com/schmitthub/clawker --skill writing-tests-schmitthub

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, well-structured tests in the clawker Go codebase requires knowing which fakes, mocks, and test seams exist for each package. This Skill provides the complete testing patterns so agents and developers write tests that match project conventions instead of inventing ad-hoc mocks. ## Core Features & Use Cases - DAG-driven test infrastructure: Explains which packages provide fakes and mocks (docker/mocks, config/mocks, gittest, whailtest) and when to add missing test infrastructure for a DAG node. - Command test tiers: Documents the three-tier pattern for CLI commands — Tier 1 flag parsing via the runF trapdoor, Tier 2 full-pipeline tests via the Cobra+Factory pattern, and Tier 3 direct unit tests. - E2E and golden file testing: Covers the test/e2e harness for running real containers, isolated XDG environments via testenv, and golden file regeneration with GOLDEN_UPDATE=1. - Use Case: When adding a new CLI command, use this Skill to write a Tier 1 flag-parsing test with the runF seam and a Tier 2 integration test injecting a FakeClient through the Factory. ## Quick Start Use the writing-tests skill to add Tier 1 and Tier 2 tests for the new stop command using the Factory and FakeClient patterns.

Frequently Asked Questions about writing-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test a Cobra CLI command in Go without a Docker daemon?▼

Use the Cobra+Factory pattern: construct the command with NewCmd(f, nil) so the real run function executes, and inject a FakeClient through the Factory's Client closure. The fake runs real docker-layer code through whail's label-filtering jail without needing a daemon.

What is the runF trapdoor pattern for testing CLI flag parsing?▼

The runF parameter on every NewCmd constructor intercepts the Options struct before the run function executes. Pass a closure that captures the options and returns nil, letting you verify flag-to-Options mapping without running business logic or Docker calls.

Which config test helper should I use: NewBlankConfig, NewFromString, or NewIsolatedTestConfig?▼

Use NewBlankConfig for defaults in command tests, NewFromString when you need specific YAML values for schema or parsing tests, and NewIsolatedTestConfig for mutation tests requiring a real Set and Write round-trip through file-backed storage.

How do I run e2e tests with real containers in clawker?▼

Use the test/e2e/harness package with real constructors in FactoryOptions, then call h.NewIsolatedFS for isolated XDG directories. Methods like RunInContainer, ExecInContainer, and Run execute commands through the full CLI pipeline and return ExitCode, Stdout, and Stderr.

When should I add test infrastructure to a package instead of mocking inline?▼

Add test infrastructure whenever a DAG node lacks fakes, interfaces, or fixtures that downstream packages need. Inline ad-hoc mocks and copy-pasted fakes are anti-patterns; each package should provide a mocks or test subpackage so dependents can mock the entire chain below them.