Files
cloud-services/pkg/health/postgres_test.go

39 lines
821 B
Go

package health_test
import (
"context"
"testing"
"github.com/fiskerinc/cloud-services/pkg/health"
"github.com/fiskerinc/cloud-services/pkg/testhelper"
"github.com/go-pg/pg/v10/orm"
"github.com/pkg/errors"
)
func TestPostgresCheck(t *testing.T) {
mock := MockPostgres{}
check := health.NewPostgresCheck(&mock)
err := check(context.Background())
testhelper.NoError(t, "No error", err)
mock.PingError = errors.New("ping error")
err = check(context.Background())
testhelper.Error(t, "Ping error", err)
}
type MockPostgres struct {
OrmResult orm.Result
PingError error
ExecError error
}
func (m *MockPostgres) Ping(ctx context.Context) error {
return m.PingError
}
func (m *MockPostgres) Exec(query interface{}, params ...interface{}) (res orm.Result, err error) {
return m.OrmResult, m.ExecError
}