github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/utils/unittest/lifecycle.go (about) 1 package unittest 2 3 import ( 4 "github.com/stretchr/testify/mock" 5 ) 6 7 // ReadyDoneify sets up a generated mock to respond to Ready and Done 8 // lifecycle methods. Any mock type generated by mockery can be used. 9 func ReadyDoneify(toMock interface{}) { 10 11 mockable, ok := toMock.(interface { 12 On(string, ...interface{}) *mock.Call 13 }) 14 if !ok { 15 panic("attempted to mock invalid type") 16 } 17 18 rwch := make(chan struct{}) 19 var ch <-chan struct{} = rwch 20 close(rwch) 21 22 mockable.On("Ready").Return(ch).Maybe() 23 mockable.On("Done").Return(ch).Maybe() 24 }