Skip to content

feat(server): load mocks from a file at startup (--init-mocks)#331

Merged
gwleclerc merged 2 commits into
mainfrom
feat/init-mocks
Jul 19, 2026
Merged

feat(server): load mocks from a file at startup (--init-mocks)#331
gwleclerc merged 2 commits into
mainfrom
feat/init-mocks

Conversation

@gwleclerc

Copy link
Copy Markdown
Collaborator

What

Add --init-mocks / SMOCKER_INIT_MOCKS: a YAML file of mocks — the exact POST /mocks format — loaded into a fresh init-mocks session when the mocks service is constructed.

This gives a declarative, dependency-free way to have mocks present on boot, without an init container or a post-start API call — handy in Kubernetes (mount a ConfigMap and point --init-mocks at it).

Design

  • Read-only: the seeded mocks are never written back.
  • Mutually exclusive with --persistence-directory: seeding a fixed set and resuming/rewriting persisted state are opposite intents (both define the boot state → ambiguous on restart, and a read-only ConfigMap mount can't be written to anyway). Setting both fails fast at startup with a clear message.
  • No format or API change: reuses the existing mock YAML format; the loading lives in services.NewMocks alongside how persisted sessions are loaded.

Verified

  • go build / go vet / go test ./server/... green; new unit tests cover the happy path (session name + count), a missing file, and an invalid mock.
  • Manual smoke: --init-mocks seeds an init-mocks session and the mock server serves the loaded mocks; --init-mocks + --persistence-directory refuses to start; a missing/invalid file exits with a clear error.

Follow-ups (not in this PR)

  • Document the flag on smocker.dev.
  • Optional venom integration test.

Addresses #217 and #222.

🤖 Generated with Claude Code

gwleclerc and others added 2 commits July 19, 2026 20:27
Add --init-mocks / SMOCKER_INIT_MOCKS: a YAML file of mocks (the exact POST
/mocks format) loaded into a fresh "init-mocks" session when the mocks service
is constructed. Useful for declarative, ephemeral setups (e.g. a Kubernetes
ConfigMap) where mocks should be present on boot without an API call.

It's read-only (never written back) and mutually exclusive with
--persistence-directory: seeding a fixed set and resuming/rewriting persisted
state are opposite intents, so setting both fails fast at startup.

Addresses #217 / #222.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The --init-mocks flag usage string and the mutual-exclusivity error message
each exceeded the 150-char limit; split them across lines. No behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gwleclerc
gwleclerc merged commit 18f7071 into main Jul 19, 2026
6 checks passed
@gwleclerc
gwleclerc deleted the feat/init-mocks branch July 19, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant