feat: add Go migration compatibility foundation
This commit is contained in:
1 parent
7de3300034
commit
716a8031b1
27 files changed
+2582
No files matched your search
@@ -0,0 +1,62 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOpenLocalReturnsStoreWithoutPool(t *testing.T) {
|
||||
module, err := Open(context.Background(), Config{Backend: BackendLocal})
|
||||
if err != nil {
|
||||
t.Fatalf("Open() error = %v", err)
|
||||
}
|
||||
if module.Store == nil {
|
||||
t.Fatal("Store = nil")
|
||||
}
|
||||
module.Close()
|
||||
if err := module.Store.Readiness(context.Background()); err != nil {
|
||||
t.Fatalf("Readiness() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenPostgresDoesNotProbeBeforeReadiness(t *testing.T) {
|
||||
module, err := Open(context.Background(), Config{
|
||||
Backend: BackendPostgres,
|
||||
DatabaseURL: "postgresql://app:secret@127.0.0.1:1/app",
|
||||
SSLMode: SSLDisable,
|
||||
PoolMax: 1,
|
||||
ApplicationName: "zhinian-go-test",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Open() error = %v; connection failures belong to readiness", err)
|
||||
}
|
||||
module.Close()
|
||||
}
|
||||
|
||||
func TestParseConfigIgnoresPostgresTLSSettingsForLocalBackend(t *testing.T) {
|
||||
cfg, err := ParseConfig(env(map[string]string{
|
||||
"ZHINIAN_DATA_BACKEND": "local",
|
||||
"DATABASE_SSL_MODE": "verify-full",
|
||||
"DATABASE_CA_CERT_PATH": "/missing/ca.pem",
|
||||
"DATABASE_POOL_MAX": "0",
|
||||
"DATABASE_CONNECTION_TIMEOUT_MS": "invalid",
|
||||
}), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseConfig() error = %v", err)
|
||||
}
|
||||
if cfg.Backend != BackendLocal || cfg.TLSConfig != nil {
|
||||
t.Fatalf("config = %+v", cfg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenPostgresRejectsInvalidConfiguredTLSMode(t *testing.T) {
|
||||
_, err := Open(context.Background(), Config{
|
||||
Backend: BackendPostgres,
|
||||
DatabaseURL: "postgresql://app:secret@db.example/app",
|
||||
SSLMode: SSLMode("prefer"),
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), "DATABASE_SSL_MODE") {
|
||||
t.Fatalf("Open() error = %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user