Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
38
pkg/health/postgres_test.go
Normal file
38
pkg/health/postgres_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package health_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"fiskerinc.com/modules/health"
|
||||
"fiskerinc.com/modules/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
|
||||
}
|
||||
Reference in New Issue
Block a user