github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/model/job/broker_mock.go (about)

     1  package job
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/cozy/cozy-stack/pkg/prefixer"
     8  	"github.com/stretchr/testify/mock"
     9  )
    10  
    11  // BrokerMock is a mock implementation of [Broker].
    12  type BrokerMock struct {
    13  	mock.Mock
    14  }
    15  
    16  func NewBrokerMock(t *testing.T) *BrokerMock {
    17  	m := new(BrokerMock)
    18  
    19  	m.Test(t)
    20  	t.Cleanup(func() { m.AssertExpectations(t) })
    21  
    22  	return m
    23  }
    24  
    25  // StartWorkers mock method.
    26  func (m *BrokerMock) StartWorkers(workersList WorkersList) error {
    27  	return m.Called(workersList).Error(0)
    28  }
    29  
    30  // ShutdownWorkers mock method.
    31  func (m *BrokerMock) ShutdownWorkers(ctx context.Context) error {
    32  	return m.Called().Error(0)
    33  }
    34  
    35  // PushJob mock method.
    36  func (m *BrokerMock) PushJob(db prefixer.Prefixer, request *JobRequest) (*Job, error) {
    37  	args := m.Called(db, request)
    38  
    39  	if args.Get(0) == nil {
    40  		return nil, args.Error(1)
    41  	}
    42  
    43  	return args.Get(0).(*Job), args.Error(1)
    44  }
    45  
    46  // WorkerQueueLen mock method.
    47  func (m *BrokerMock) WorkerQueueLen(workerType string) (int, error) {
    48  	args := m.Called(workerType)
    49  
    50  	return args.Int(0), args.Error(1)
    51  }
    52  
    53  // WorkerIsReserved mock method.
    54  func (m *BrokerMock) WorkerIsReserved(workerType string) (bool, error) {
    55  	args := m.Called(workerType)
    56  
    57  	return args.Bool(0), args.Error(1)
    58  }
    59  
    60  // WorkersTypes mock method.
    61  func (m *BrokerMock) WorkersTypes() []string {
    62  	args := m.Called()
    63  
    64  	if args.Get(0) == nil {
    65  		return nil
    66  	}
    67  
    68  	return args.Get(0).([]string)
    69  }