Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export clock method to allow assignable in other packages #242

Merged
merged 1 commit into from
Sep 17, 2020

Conversation

flisky
Copy link
Contributor

@flisky flisky commented Sep 12, 2020

For example:

cache := bigcache.NewBigCache(bigcache.DefaultConfig(time.Minute))
clock := &mockedClock{}
rf := reflect.ValueOf(cache).Elem().FieldByName("clock")
reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem().Set(reflect.ValueOf(clock))

Without this change, it panics with value of type *cache_test.mockedClock is not assignable to type bigcache.clock

And it goes to *cache_test.mockedClock cannot implement bigcache.Clock as it has a non-exported method and is defined in a difference package if we only export clock interface.

Fix #241

For example:

```
cache := bigcache.NewBigCache(bigcache.DefaultConfig(time.Minute))
clock := &mockedClock{}
rf := reflect.ValueOf(cache).Elem().FieldByName("clock")
reflect.NewAt(rf.Type(), unsafe.Pointer(rf.UnsafeAddr())).Elem().Set(reflect.ValueOf(clock))
```

Without this change, it panics with `value of type *cache_test.mockedClock is not assignable to type bigcache.clock`

And it goes to `*cache_test.mockedClock cannot implement bigcache.Clock as it has a non-exported method and is defined in a difference package`
if we only export clock interface.
Copy link
Collaborator

@siennathesane siennathesane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support mocking clock in other projects
3 participants