From b304d40bd5851db56bafd48661dd33ecebb25952 Mon Sep 17 00:00:00 2001 From: agiledragon Date: Sun, 23 Sep 2018 16:31:52 +0800 Subject: [PATCH] test patch pair --- test/patch_pair_test.go | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/patch_pair_test.go diff --git a/test/patch_pair_test.go b/test/patch_pair_test.go new file mode 100644 index 0000000..943aa74 --- /dev/null +++ b/test/patch_pair_test.go @@ -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) + }) + + }) +}