MCPcopy Index your code
hub / github.com/dhuan/mock

github.com/dhuan/mock @v1.4.16

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.4.16 ↗ · + Follow
641 symbols 2,578 edges 84 files 2 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

mock

Go Reference Go Report Card

mock is an API utility - it lets you:

  • define API routes easily through API configuration files or through command-line parameters.
  • use shells scripts as response handlers. Or any other type of program can act as response handlers.
  • test your API - make assertions on whether an endpoint was requested.

The fastest way to learn and understand mock is to see the examples page.

Quick links

Getting started

$ mock serve --port 3000 \
  --get "/time-now" \
  --exec 'printf "Now it is %s" $(date +"%H:%M") | mock write' \
  --post "/shut-down/{application}" \
  --exec 'killall $(mock get-route-param application)'

Let's test it out:

$ curl localhost:3000/time-now
# Prints out:
Now it is 22:00

$ curl -X POST localhost:3000/shut-down/mock
# Shuts down the server!

mock lets you also extend other APIs (or any HTTP service, for that matter.) Suppose you want to add a new route to an existing API running at example.com:

$ mock serve --port 3000 \
  --base example.com \
  --get 'some-new-route' \
  --exec 'printf "Hello, world!" | mock write' 

With the --base example.com option above, your API will act as proxy to that other website, and extend it with an extra route GET /some-new-route. Look up "Base APIs" in the docs for more details.

There are many other ways of further customising your APIs with mock. Read further through the guide to learn.

Installing

mock is distributed as a single-file executable. Check the releases page and download the latest tarball.

License

mock is licensed under MIT. For more information check the LICENSE file.

Extension points exported contracts — how you extend this code

MockFs (Interface)
(no doc) [2 implementers]
internal/types/types.go
TestOperationFunc (FuncType)
(no doc)
internal/test_unit_utils/test_unit_utils.go
KillMockFunc (FuncType)
(no doc)
tests/e2e/utils/utils.go

Core symbols most depended-on inside this repo

StringMatches
called by 127
tests/e2e/utils/utils.go
RunTest
called by 66
tests/e2e/utils/utils.go
RunTestWithNoConfigAndWithArgs
called by 62
tests/e2e/utils/utils.go
StatusCodeMatches
called by 53
tests/e2e/utils/utils.go
NewGetTestRequest
called by 48
tests/e2e/utils/utils.go
LineEquals
called by 39
tests/e2e/utils/utils.go
HeadersMatch
called by 37
tests/e2e/utils/utils.go
RunTest4
called by 31
tests/e2e/utils/utils.go

Shape

Function 573
Struct 38
Method 19
TypeAlias 8
FuncType 2
Interface 1

Languages

Go100%

Modules by API surface

tests/e2e/utils/utils.go81 symbols
internal/utils/utils.go45 symbols
internal/cmd/serve.go37 symbols
internal/mock/response.go35 symbols
tests/e2e/responses_test.go27 symbols
internal/mock/mock_test.go26 symbols
internal/test_unit_utils/test_unit_utils.go24 symbols
internal/mock/response_test.go21 symbols
tests/e2e/base_api_test.go18 symbols
internal/args2config/args2config_test.go16 symbols
internal/args2config/args2config.go16 symbols
tests/e2e/middlewares_before_response_test.go14 symbols

For agents

$ claude mcp add mock \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact