ipld-eth-server/pkg/fakes/mock_header_repository.go

51 lines
1.8 KiB
Go
Raw Normal View History

package fakes
import (
. "github.com/onsi/gomega"
"github.com/vulcanize/vulcanizedb/pkg/core"
)
type MockHeaderRepository struct {
2018-07-24 16:38:49 +00:00
createOrUpdateHeaderCallCount int
createOrUpdateHeaderErr error
2018-07-24 16:38:49 +00:00
createOrUpdateHeaderPassedBlockNumbers []int64
createOrUpdateHeaderReturnID int64
missingBlockNumbers []int64
}
func NewMockHeaderRepository() *MockHeaderRepository {
return &MockHeaderRepository{}
}
2018-07-24 16:38:49 +00:00
func (repository *MockHeaderRepository) SetCreateOrUpdateHeaderReturnID(id int64) {
repository.createOrUpdateHeaderReturnID = id
}
func (repository *MockHeaderRepository) SetCreateOrUpdateHeaderReturnErr(err error) {
repository.createOrUpdateHeaderErr = err
}
func (repository *MockHeaderRepository) SetMissingBlockNumbers(blockNumbers []int64) {
repository.missingBlockNumbers = blockNumbers
}
func (repository *MockHeaderRepository) CreateOrUpdateHeader(header core.Header) (int64, error) {
2018-07-24 16:38:49 +00:00
repository.createOrUpdateHeaderCallCount++
repository.createOrUpdateHeaderPassedBlockNumbers = append(repository.createOrUpdateHeaderPassedBlockNumbers, header.BlockNumber)
return repository.createOrUpdateHeaderReturnID, repository.createOrUpdateHeaderErr
}
func (*MockHeaderRepository) GetHeader(blockNumber int64) (core.Header, error) {
return core.Header{BlockNumber: blockNumber}, nil
}
func (repository *MockHeaderRepository) MissingBlockNumbers(startingBlockNumber, endingBlockNumber int64, nodeID string) []int64 {
return repository.missingBlockNumbers
}
func (repository *MockHeaderRepository) AssertCreateOrUpdateHeaderCallCountAndPassedBlockNumbers(times int, blockNumbers []int64) {
2018-07-24 16:38:49 +00:00
Expect(repository.createOrUpdateHeaderCallCount).To(Equal(times))
Expect(repository.createOrUpdateHeaderPassedBlockNumbers).To(Equal(blockNumbers))
}