Skip to content

Commit

Permalink
Merge branch 'master' into dataManagerInterfaces-test-2
Browse files Browse the repository at this point in the history
  • Loading branch information
timl3136 authored Mar 6, 2024
2 parents 6420996 + cb39e82 commit e25a286
Show file tree
Hide file tree
Showing 15 changed files with 638 additions and 106 deletions.
1 change: 1 addition & 0 deletions cmd/server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
Expand Down
95 changes: 95 additions & 0 deletions common/domain/replication_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,98 @@ func TestReplicationQueueImpl_PublishToDLQ(t *testing.T) {
})
}
}

func TestGetReplicationMessages(t *testing.T) {

tests := []struct {
name string
lastID int64
maxCount int
task *types.ReplicationTask
wantErr bool
setupMock func(q *persistence.MockQueueManager)
}{
{
name: "successful message retrieval",
lastID: 100,
maxCount: 10,
task: &types.ReplicationTask{},
wantErr: false,
setupMock: func(q *persistence.MockQueueManager) {
q.EXPECT().ReadMessages(gomock.Any(), gomock.Eq(int64(100)), gomock.Eq(10)).Return(persistence.QueueMessageList{}, nil)
},
},
{
name: "read messages fails",
lastID: 100,
maxCount: 10,
wantErr: true,
setupMock: func(q *persistence.MockQueueManager) {
q.EXPECT().ReadMessages(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, errors.New("read error"))
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
mockQueue := persistence.NewMockQueueManager(ctrl)
rq := NewReplicationQueue(mockQueue, "testCluster", nil, nil)

tt.setupMock(mockQueue)
_, _, err := rq.GetReplicationMessages(context.Background(), tt.lastID, tt.maxCount)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
ctrl.Finish()
})
}
}

func TestUpdateAckLevel(t *testing.T) {
tests := []struct {
name string
lastID int64
cluster string
wantErr bool
setupMock func(q *persistence.MockQueueManager)
}{
{
name: "successful ack level update",
lastID: 100,
cluster: "testCluster",
wantErr: false,
setupMock: func(q *persistence.MockQueueManager) {
q.EXPECT().UpdateAckLevel(gomock.Any(), gomock.Eq(int64(100)), gomock.Eq("testCluster")).Return(nil)
},
},
{
name: "ack level update fails",
lastID: 100,
cluster: "testCluster",
wantErr: true,
setupMock: func(q *persistence.MockQueueManager) {
q.EXPECT().UpdateAckLevel(gomock.Any(), gomock.Eq(int64(100)), gomock.Eq("testCluster")).Return(errors.New("update error"))
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
mockQueue := persistence.NewMockQueueManager(ctrl)

rq := NewReplicationQueue(mockQueue, "testCluster", nil, nil)
tt.setupMock(mockQueue)
err := rq.UpdateAckLevel(context.Background(), tt.lastID, tt.cluster)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
ctrl.Finish()
})
}
}
Loading

0 comments on commit e25a286

Please sign in to comment.