27 lines
704 B
Go
27 lines
704 B
Go
package dbpool
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNewPostgresPool_ParseConfigError(t *testing.T) {
|
|
_, err := NewPostgresPool(context.Background(), "://invalid-url", PoolConfig{})
|
|
if err == nil || !strings.Contains(err.Error(), "parse postgres pool config") {
|
|
t.Fatalf("expected parse config error, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestNewPostgresPool_PingError(t *testing.T) {
|
|
_, err := NewPostgresPool(
|
|
context.Background(),
|
|
"postgres://postgres:postgres@127.0.0.1:1/appdb?sslmode=disable",
|
|
PoolConfig{ConnectionAcquireWait: 20 * time.Millisecond},
|
|
)
|
|
if err == nil || !strings.Contains(err.Error(), "ping postgres") {
|
|
t.Fatalf("expected ping error, got %v", err)
|
|
}
|
|
}
|