Add periodicsync test
This commit is contained in:
parent
53d10dc597
commit
aaaab9deca
@ -1,3 +1,4 @@
|
||||
//go:generate mockgen -destination mock_diffservice/mock_diffservice.go github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice DiffSyncer
|
||||
package diffservice
|
||||
|
||||
import (
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice (interfaces: DiffSyncer)
|
||||
|
||||
// Package mock_diffservice is a generated GoMock package.
|
||||
package mock_diffservice
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
// MockDiffSyncer is a mock of DiffSyncer interface.
|
||||
type MockDiffSyncer struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockDiffSyncerMockRecorder
|
||||
}
|
||||
|
||||
// MockDiffSyncerMockRecorder is the mock recorder for MockDiffSyncer.
|
||||
type MockDiffSyncerMockRecorder struct {
|
||||
mock *MockDiffSyncer
|
||||
}
|
||||
|
||||
// NewMockDiffSyncer creates a new mock instance.
|
||||
func NewMockDiffSyncer(ctrl *gomock.Controller) *MockDiffSyncer {
|
||||
mock := &MockDiffSyncer{ctrl: ctrl}
|
||||
mock.recorder = &MockDiffSyncerMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockDiffSyncer) EXPECT() *MockDiffSyncerMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Sync mocks base method.
|
||||
func (m *MockDiffSyncer) Sync(arg0 context.Context) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Sync", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Sync indicates an expected call of Sync.
|
||||
func (mr *MockDiffSyncerMockRecorder) Sync(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sync", reflect.TypeOf((*MockDiffSyncer)(nil).Sync), arg0)
|
||||
}
|
||||
39
common/commonspace/diffservice/periodicsync_test.go
Normal file
39
common/commonspace/diffservice/periodicsync_test.go
Normal file
@ -0,0 +1,39 @@
|
||||
package diffservice
|
||||
|
||||
import (
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/diffservice/mock_diffservice"
|
||||
"github.com/golang/mock/gomock"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPeriodicSync_Run(t *testing.T) {
|
||||
// setup
|
||||
//ctx := context.Background()
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
l := logger.NewNamed("sync")
|
||||
diffSyncer := mock_diffservice.NewMockDiffSyncer(ctrl)
|
||||
t.Run("diff syncer 1 time", func(t *testing.T) {
|
||||
secs := 0
|
||||
pSync := newPeriodicSync(secs, diffSyncer, l)
|
||||
|
||||
diffSyncer.EXPECT().Sync(gomock.Any()).Times(1).Return(nil)
|
||||
|
||||
pSync.Run()
|
||||
pSync.Close()
|
||||
})
|
||||
|
||||
t.Run("diff syncer 2 times", func(t *testing.T) {
|
||||
secs := 1
|
||||
|
||||
pSync := newPeriodicSync(secs, diffSyncer, l)
|
||||
diffSyncer.EXPECT().Sync(gomock.Any()).Times(2).Return(nil)
|
||||
|
||||
pSync.Run()
|
||||
time.Sleep(time.Second * time.Duration(secs))
|
||||
pSync.Close()
|
||||
})
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user