Skip to content

Commit

Permalink
fix: switch monkeypatching implementation (argoproj#4462)
Browse files Browse the repository at this point in the history
Signed-off-by: John Pitman <[email protected]>
  • Loading branch information
jopit authored Sep 30, 2020
1 parent 0226190 commit 7b60548
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/argoproj/argo-cd
go 1.14

require (
bou.ke/monkey v1.0.1
github.com/Masterminds/semver v1.5.0
github.com/TomOnTime/utfutil v0.0.0-20180511104225-09c41003ee1d
github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6 // indirect
Expand Down Expand Up @@ -56,6 +55,7 @@ require (
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
github.com/undefinedlabs/go-mpatch v1.0.6
github.com/yuin/gopher-lua v0.0.0-20190115140932-732aa6820ec4
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
golang.org/x/net v0.0.0-20200513185701-a91f0712d120
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690/go.mod h1:Ulb78X89vxKYgdL24HMTiXYHlyHEvruOj1ZPlqeNEZM=
bou.ke/monkey v1.0.1 h1:zEMLInw9xvNakzUUPjfS4Ds6jYPqCFx3m7bRmG5NH2U=
bou.ke/monkey v1.0.1/go.mod h1:FgHuK96Rv2Nlf+0u1OOVDpCMdsWyOFmeeketDHE7LIg=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
Expand Down Expand Up @@ -679,6 +677,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ultraware/funlen v0.0.1/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
github.com/ultraware/funlen v0.0.2/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
github.com/undefinedlabs/go-mpatch v1.0.6 h1:h8q5ORH/GaOE1Se1DMhrOyljXZEhRcROO7agMqWXCOY=
github.com/undefinedlabs/go-mpatch v1.0.6/go.mod h1:TyJZDQ/5AgyN7FSLiBJ8RO9u2c6wbtRvK827b6AVqY4=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
Expand Down
11 changes: 7 additions & 4 deletions resource_customizations/custom_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"testing"
"time"

"bou.ke/monkey"
"github.com/undefinedlabs/go-mpatch"

"github.com/argoproj/gitops-engine/pkg/diff"
"github.com/ghodss/yaml"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -88,11 +89,13 @@ func TestLuaResourceActionsScript(t *testing.T) {
assert.NoError(t, err)

// freeze time so that lua test has predictable time output (will return 0001-01-01T00:00:00Z)
patch := monkey.Patch(time.Now, func() time.Time { return time.Time{} })
patch, err := mpatch.PatchMethod(time.Now, func() time.Time { return time.Time{} })
assert.NoError(t, err)
result, err := vm.ExecuteResourceAction(obj, action.ActionLua)
patch.Unpatch()

assert.NoError(t, err)
err = patch.Unpatch()
assert.NoError(t, err)

expectedObj := getObj(filepath.Join(dir, test.ExpectedOutputPath))
// Ideally, we would use a assert.Equal to detect the difference, but the Lua VM returns a object with float64 instead of the original int32. As a result, the assert.Equal is never true despite that the change has been applied.
diffResult, err := diff.Diff(expectedObj, result, testNormalizer{}, diff.GetDefaultDiffOptions())
Expand Down

0 comments on commit 7b60548

Please sign in to comment.