Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/agiledragon/gomonkey
gomonkey is a library to make monkey patching in unit tests easy
https://github.com/agiledragon/gomonkey
function function-variable global-variable gomonkey interface member-method patch private-method sequence
Last synced: 24 days ago
JSON representation
gomonkey is a library to make monkey patching in unit tests easy
- Host: GitHub
- URL: https://github.com/agiledragon/gomonkey
- Owner: agiledragon
- License: mit
- Created: 2018-08-15T13:29:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-05T15:04:47.000Z (4 months ago)
- Last Synced: 2024-10-01T23:23:44.143Z (about 1 month ago)
- Topics: function, function-variable, global-variable, gomonkey, interface, member-method, patch, private-method, sequence
- Language: Go
- Homepage:
- Size: 92.8 KB
- Stars: 1,996
- Watchers: 26
- Forks: 179
- Open Issues: 51
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- go-awesome - gomonkey - monkey patch, stack functions, variables etc. to facilitate unit testing, fork of [Monkey](https://github.com/bouk / Ape) (Open source library / Test)
- my-awesome - agiledragon/gomonkey - variable,global-variable,gomonkey,interface,member-method,patch,private-method,sequence pushed_at:2024-07 star:2.0k fork:0.2k gomonkey is a library to make monkey patching in unit tests easy (Go)
README
# gomonkey
gomonkey is a library to make monkey patching in unit tests easy, and the core idea of monkey patching comes from [Bouke](https://github.com/bouk), you can read [this blogpost](https://bou.ke/blog/monkey-patching-in-go/) 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- OS
- Linux
- MAC OS X
- Windows## Installation
- below v2.1.0, for example v2.0.2
```go
$ go get github.com/agiledragon/[email protected]
```
- v2.1.0 and above, for example v2.11.0
```go
$ go get github.com/agiledragon/gomonkey/[email protected]
```## Test Method
```go
$ cd test
$ go test -gcflags=all=-l
```## Using gomonkey
Please refer to the test cases as idioms, very complete and detailed.