gomonkey
gomonkey copied to clipboard
feature: replace the arguments of a function
Is there a more appropriate way to change the parameters of a function?
more complicated way....
var patchReadDir = gomonkey.NewPatches()
var readDir func(name string) ([]os.DirEntry, error)
readDir = func(name string) ([]os.DirEntry, error) {
patchReadDir.Reset()
defer patchReadDir.ApplyFunc(os.ReadDir, readDir)
return os.ReadDir(filepath.Join(c.baseDir, name))
}
patchReadDir.ApplyFunc(os.ReadDir, readDir)
c.patches = append(c.patches, patchReadDir)
I think it's related to https://github.com/agiledragon/gomonkey/issues/103