Skip to content

Commit

Permalink
test patch pair
Browse files Browse the repository at this point in the history
  • Loading branch information
agiledragon committed Sep 23, 2018
1 parent 2a80388 commit b304d40
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/patch_pair_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package test

import (
. "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 b304d40

Please sign in to comment.