123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- package mock
- import (
- "github.com/qor5/admin/worker"
- "sync"
- )
- var _ worker.Queue = &QueueMock{}
- type QueueMock struct {
-
- AddFunc func(queJobInterface worker.QueJobInterface) error
-
- KillFunc func(queJobInterface worker.QueJobInterface) error
-
- ListenFunc func(jobDefs []*worker.QorJobDefinition, getJob func(qorJobID uint) (worker.QueJobInterface, error)) error
-
- RemoveFunc func(queJobInterface worker.QueJobInterface) error
-
- calls struct {
-
- Add []struct {
-
- QueJobInterface worker.QueJobInterface
- }
-
- Kill []struct {
-
- QueJobInterface worker.QueJobInterface
- }
-
- Listen []struct {
-
- JobDefs []*worker.QorJobDefinition
-
- GetJob func(qorJobID uint) (worker.QueJobInterface, error)
- }
-
- Remove []struct {
-
- QueJobInterface worker.QueJobInterface
- }
- }
- lockAdd sync.RWMutex
- lockKill sync.RWMutex
- lockListen sync.RWMutex
- lockRemove sync.RWMutex
- }
- func (mock *QueueMock) Add(queJobInterface worker.QueJobInterface) error {
- if mock.AddFunc == nil {
- panic("QueueMock.AddFunc: method is nil but Queue.Add was just called")
- }
- callInfo := struct {
- QueJobInterface worker.QueJobInterface
- }{
- QueJobInterface: queJobInterface,
- }
- mock.lockAdd.Lock()
- mock.calls.Add = append(mock.calls.Add, callInfo)
- mock.lockAdd.Unlock()
- return mock.AddFunc(queJobInterface)
- }
- func (mock *QueueMock) AddCalls() []struct {
- QueJobInterface worker.QueJobInterface
- } {
- var calls []struct {
- QueJobInterface worker.QueJobInterface
- }
- mock.lockAdd.RLock()
- calls = mock.calls.Add
- mock.lockAdd.RUnlock()
- return calls
- }
- func (mock *QueueMock) Kill(queJobInterface worker.QueJobInterface) error {
- if mock.KillFunc == nil {
- panic("QueueMock.KillFunc: method is nil but Queue.Kill was just called")
- }
- callInfo := struct {
- QueJobInterface worker.QueJobInterface
- }{
- QueJobInterface: queJobInterface,
- }
- mock.lockKill.Lock()
- mock.calls.Kill = append(mock.calls.Kill, callInfo)
- mock.lockKill.Unlock()
- return mock.KillFunc(queJobInterface)
- }
- func (mock *QueueMock) KillCalls() []struct {
- QueJobInterface worker.QueJobInterface
- } {
- var calls []struct {
- QueJobInterface worker.QueJobInterface
- }
- mock.lockKill.RLock()
- calls = mock.calls.Kill
- mock.lockKill.RUnlock()
- return calls
- }
- func (mock *QueueMock) Listen(jobDefs []*worker.QorJobDefinition, getJob func(qorJobID uint) (worker.QueJobInterface, error)) error {
- if mock.ListenFunc == nil {
- panic("QueueMock.ListenFunc: method is nil but Queue.Listen was just called")
- }
- callInfo := struct {
- JobDefs []*worker.QorJobDefinition
- GetJob func(qorJobID uint) (worker.QueJobInterface, error)
- }{
- JobDefs: jobDefs,
- GetJob: getJob,
- }
- mock.lockListen.Lock()
- mock.calls.Listen = append(mock.calls.Listen, callInfo)
- mock.lockListen.Unlock()
- return mock.ListenFunc(jobDefs, getJob)
- }
- func (mock *QueueMock) ListenCalls() []struct {
- JobDefs []*worker.QorJobDefinition
- GetJob func(qorJobID uint) (worker.QueJobInterface, error)
- } {
- var calls []struct {
- JobDefs []*worker.QorJobDefinition
- GetJob func(qorJobID uint) (worker.QueJobInterface, error)
- }
- mock.lockListen.RLock()
- calls = mock.calls.Listen
- mock.lockListen.RUnlock()
- return calls
- }
- func (mock *QueueMock) Remove(queJobInterface worker.QueJobInterface) error {
- if mock.RemoveFunc == nil {
- panic("QueueMock.RemoveFunc: method is nil but Queue.Remove was just called")
- }
- callInfo := struct {
- QueJobInterface worker.QueJobInterface
- }{
- QueJobInterface: queJobInterface,
- }
- mock.lockRemove.Lock()
- mock.calls.Remove = append(mock.calls.Remove, callInfo)
- mock.lockRemove.Unlock()
- return mock.RemoveFunc(queJobInterface)
- }
- func (mock *QueueMock) RemoveCalls() []struct {
- QueJobInterface worker.QueJobInterface
- } {
- var calls []struct {
- QueJobInterface worker.QueJobInterface
- }
- mock.lockRemove.RLock()
- calls = mock.calls.Remove
- mock.lockRemove.RUnlock()
- return calls
- }
|