Skip to content

export clock method to allow assignable in other packages#242

Merged
siennathesane merged 1 commit intoallegro:masterfrom
flisky:master
Sep 17, 2020
Merged

export clock method to allow assignable in other packages#242
siennathesane merged 1 commit intoallegro:masterfrom
flisky:master

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