github.com/agiledragon/gomonkey/v2@v2.11.1-0.20240427155748-d56c6823ec17/README.md (about)

     1  # gomonkey
     2  
     3  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.
     4  
     5  ## Features
     6  
     7  + support a patch for a function
     8  + support a patch for a public member method
     9  + support a patch for a private member method
    10  + support a patch for a interface
    11  + support a patch for a function variable
    12  + support a patch for a global variable
    13  + support patches of a specified sequence for a function
    14  + support patches of a specified sequence for a member method
    15  + support patches of a specified sequence for a interface
    16  + support patches of a specified sequence for a function variable
    17  
    18  ## Notes
    19  + 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).
    20  + 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.
    21  
    22  ## Supported Platform:
    23  
    24  - ARCH
    25    - amd64
    26    - arm64
    27    - 386
    28    - loong64
    29  
    30  - OS
    31    - Linux
    32    - MAC OS X
    33    - Windows
    34  
    35  ## Installation
    36  - below v2.1.0, for example v2.0.2
    37  ```go
    38  $ go get github.com/agiledragon/gomonkey@v2.0.2
    39  ```
    40  - v2.1.0 and above, for example v2.11.0
    41  ```go
    42  $ go get github.com/agiledragon/gomonkey/v2@v2.11.0
    43  ```
    44  
    45  ## Test Method
    46  ```go
    47  $ cd test 
    48  $ go test -gcflags=all=-l
    49  ```
    50  
    51  ## Using gomonkey
    52  
    53  Please refer to the test cases as idioms, very complete and detailed.
    54