Gate the merge on unit coverage for the three packages that previously had none: env precedence, migrate/query, and claim/heartbeat/reap. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1015 B
Go
46 lines
1015 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestConnectRejectsUnreachableDSN(t *testing.T) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
|
defer cancel()
|
|
_, err := Connect(ctx, "postgres://cc:cc@127.0.0.1:1/control_center?sslmode=disable&connect_timeout=1")
|
|
if err == nil {
|
|
t.Fatal("expected connect error")
|
|
}
|
|
}
|
|
|
|
func TestMigrateAndQuery(t *testing.T) {
|
|
dsn := os.Getenv("TEST_CC_DB_DSN")
|
|
if dsn == "" {
|
|
t.Skip("TEST_CC_DB_DSN not set")
|
|
}
|
|
_, thisFile, _, _ := runtime.Caller(0)
|
|
dir := filepath.Join(filepath.Dir(thisFile), "..", "..", "..", "deploy", "control-center", "goose")
|
|
ctx := context.Background()
|
|
if err := Migrate(ctx, dsn, dir); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
st, err := Connect(ctx, dsn)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(st.Close)
|
|
|
|
var n int
|
|
if err := st.Pool.QueryRow(ctx, `SELECT count(*) FROM cc_tasks`).Scan(&n); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n < 0 {
|
|
t.Fatalf("count = %d", n)
|
|
}
|
|
}
|