cch123 / supermonkey

Patch all Go functions for testing
MIT License
254 stars 17 forks source link

fix: PatchByFullSymbolName panic when `Restore` from unpatch #16

Closed u2386 closed 3 years ago

u2386 commented 3 years ago

15

ioworker0 commented 3 years ago

As far as my concern, the restore method that is redundant, but I'd like to try to fix it (please wait a moment).

ioworker0 commented 3 years ago

This is my way #17 @u2386

u2386 commented 3 years ago

the restore method that is redundant

Restore is quite useful, e.g

var guard *supermonkey.PatchGuard
guard = supermonkey.PatchByFullSymbolName(time.Now, func() time.Time {
    guard.Unpatch()
    defer guard.Restore()

    actual := time.Now()
    manipulated := actual.Add(time.Hour)
    return manipulated
})
cch123 commented 3 years ago

the restore method that is redundant

Restore is quite useful, e.g

var guard *supermonkey.PatchGuard
guard = supermonkey.PatchByFullSymbolName(time.Now, func() time.Time {
  guard.Unpatch()
  defer guard.Restore()

  actual := time.Now()
  manipulated := actual.Add(time.Hour)
  return manipulated
})

@Mutated1994

ioworker0 commented 3 years ago

the restore method that is redundant

Restore is quite useful, e.g

var guard *supermonkey.PatchGuard
guard = supermonkey.PatchByFullSymbolName(time.Now, func() time.Time {
    guard.Unpatch()
    defer guard.Restore()

    actual := time.Now()
    manipulated := actual.Add(time.Hour)
    return manipulated
})

@Mutated1994

Sorry, I'm late. @u2386 Dude, I've changed my mind. You are right in your case! @u2386 @cch123 I've fixed this issue. #17

cch123 commented 3 years ago

https://github.com/cch123/supermonkey/pull/17 is merged, so close this ~