Skip to content

Commit

Permalink
test CreateIndexes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbretter committed Nov 4, 2024
1 parent 10cbd66 commit 343b2ca
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,41 @@ func TestQueue_Selftest(t *testing.T) {
} else if tt.error2 != nil {
assert.Equal(t, tt.error2, err)
} else {
assert.Equal(t, nil, err)
assert.Nil(t, err)
}
})
}
}

func TestQueue_CreateIndexes(t *testing.T) {

tests := []struct {
name string
error error
}{
{
name: "Success",
},
{
name: "Error",
error: errors.New("CreateIndexes failed"),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbMock := NewDbInterfaceMock(t)

q := NewQueue(dbMock)

dbMock.EXPECT().CreateIndexes([]mongo.IndexModel{{
Keys: bson.D{{"topic", 1}, {"state", 1}},
}, {
Keys: bson.D{{"meta.completed", 1}}, Options: options.Index().SetExpireAfterSeconds(3600),
}}).Return(tt.error)

err := q.CreateIndexes()
assert.Equal(t, err, tt.error)
})
}
}

0 comments on commit 343b2ca

Please sign in to comment.