Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
agiledragon committed Sep 23, 2018
1 parent b304d40 commit b6742d5
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $ go get github.com/agiledragon/gomonkey
```
## Using gomonkey

The following just make some tests as typical examples.
The following just make some tests as idioms.
**Please refer to the test cases, very complete and detailed.**

### ApplyFunc
Expand Down Expand Up @@ -481,4 +481,62 @@ func TestApplyFuncVarSeq(t *testing.T) {
})
}

```
```

## NewPatches

```go
mport (
. "github.com/agiledragon/gomonkey"
. "github.com/smartystreets/goconvey/convey"
"testing"
"github.com/agiledragon/gomonkey/test/fake"
"encoding/json"
)

func TestPatchPair(t *testing.T) {

Convey("TestPatchPair", t, func() {

Convey("TestPatchPair", func() {
patchPairs := [][2]interface{} {
{
fake.Exec,
func(_ string, _ ...string) (string, error) {
return outputExpect, nil
},
},
{
json.Unmarshal,
func(_ []byte, v interface{}) error {
p := v.(*map[int]int)
*p = make(map[int]int)
(*p)[1] = 2
(*p)[2] = 4
return nil
},
},

}
patches := NewPatches()
defer patches.Reset()
for _, pair := range patchPairs {
patches.ApplyFunc(pair[0], pair[1])
}

output, err := fake.Exec("", "")
So(err, ShouldEqual, nil)
So(output, ShouldEqual, outputExpect)

var m map[int]int
err = json.Unmarshal(nil, &m)
So(err, ShouldEqual, nil)
So(m[1], ShouldEqual, 2)
So(m[2], ShouldEqual, 4)
})
})
}

```


0 comments on commit b6742d5

Please sign in to comment.