MCPcopy Index your code
hub / github.com/agiledragon/gomonkey

github.com/agiledragon/gomonkey @v2.14.0 sqlite

repository ↗ · DeepWiki ↗ · release v2.14.0 ↗
152 symbols 463 edges 33 files 23 documented · 15% 4 cross-repo links
README

gomonkey

gomonkey is a library to make monkey patching in unit tests easy, and the core idea of monkey patching comes from Bouke, you can read this blogpost for an explanation on how it works.

Features

  • support a patch for a function
  • support a patch for a public member method
  • support a patch for a private member method
  • support a patch for a interface
  • support a patch for a function variable
  • support a patch for a global variable
  • support patches of a specified sequence for a function
  • support patches of a specified sequence for a member method
  • support patches of a specified sequence for a interface
  • support patches of a specified sequence for a function variable

Notes

  • gomonkey fails to patch a function or a member method if inlining is enabled, please running your tests with inlining disabled by adding the command line argument that is -gcflags=-l(below go1.10) or -gcflags=all=-l(go1.10 and above).
  • A panic may happen when a goroutine is patching a function or a member method that is visited by another goroutine at the same time. That is to say, gomonkey is not threadsafe.

Supported Platform:

  • ARCH
  • amd64
  • arm64
  • 386
  • loong64
  • riscv64

  • OS

  • Linux
  • MAC OS X
  • Windows

Installation

  • below v2.1.0, for example v2.0.2
$ go get github.com/agiledragon/gomonkey@v2.0.2
  • v2.1.0 and above, for example v2.11.0
$ go get github.com/agiledragon/gomonkey/v2@v2.11.0

Test Method

$ cd test 
$ go test -gcflags=all=-l

Using gomonkey

Please refer to the test cases as idioms, very complete and detailed.

Extension points exported contracts — how you extend this code

Db (Interface)
(no doc) [2 implementers]
test/fake/fake.go
Constraint (Interface)
(no doc) [2 implementers]
dsl/constraint.go
Behavior (Interface)
(no doc) [2 implementers]
dsl/behavior.go

Core symbols most depended-on inside this repo

Reset
called by 42
patch.go
Add
called by 16
test/fake/fake.go
ReadLeaf
called by 14
test/fake/fake.go
create
called by 13
patch.go
Remove
called by 13
test/fake/fake.go
ApplyFunc
called by 12
patch.go
Retrieve
called by 11
test/fake/fake.go
Exec
called by 10
test/fake/fake.go

Shape

Function 71
Method 48
Struct 24
TypeAlias 6
Interface 3

Languages

Go100%

Modules by API surface

patch.go43 symbols
creflect/type.go25 symbols
test/fake/fake.go20 symbols
dsl/patch_builder.go9 symbols
jmp_riscv64.go6 symbols
dsl/constraint.go6 symbols
dsl/behavior.go6 symbols
dsl/factory.go4 symbols
creflect/ae1.17.go4 symbols
modify_binary_darwin.go3 symbols
modify_binary_linux.go2 symbols
jmp_loong64.go2 symbols

Dependencies from manifests, versioned

github.com/smartystreets/goconveyv1.6.4 · 1×

For agents

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

⬇ download graph artifact