34 lines
637 B
Go
34 lines
637 B
Go
package health_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"fiskerinc.com/modules/health"
|
|
"fiskerinc.com/modules/testhelper"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func TestMongoDBCheck(t *testing.T) {
|
|
mock := MockMongoDB{}
|
|
fn := func() (health.MongoConnCheckInterface, error) {
|
|
return &mock, nil
|
|
}
|
|
check := health.NewMongoDBCheck(fn)
|
|
|
|
err := check(context.Background())
|
|
testhelper.NoError(t, "No error", err)
|
|
|
|
mock.Error = errors.New("ping error")
|
|
err = check(context.Background())
|
|
testhelper.Error(t, "Ping error", err)
|
|
}
|
|
|
|
type MockMongoDB struct {
|
|
Error error
|
|
}
|
|
|
|
func (m *MockMongoDB) Ping(ctx context.Context) error {
|
|
return m.Error
|
|
}
|