feat: add PawSQL docs examples and image CI
All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m28s
All checks were successful
Build and Push Image / docker-build-and-push (push) Successful in 2m28s
This commit is contained in:
65
internal/postgres/provisioner_integration_test.go
Normal file
65
internal/postgres/provisioner_integration_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
//go:build integration
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/barkstack/pawsql/internal/config"
|
||||
)
|
||||
|
||||
func TestProvisionerCreatesPersistentPostgres18(t *testing.T) {
|
||||
const (
|
||||
database = "pawsql_integration_test"
|
||||
volume = "pawsql-integration-test-data"
|
||||
envName = "PAWSQL_INTEGRATION_POSTGRES_PASSWORD"
|
||||
)
|
||||
t.Setenv(envName, "integration-test-password")
|
||||
provisioner := NewProvisioner(nil)
|
||||
defer func() {
|
||||
_, _ = provisioner.run(context.Background(), nil, "container", "rm", "--force", containerName(database))
|
||||
_, _ = provisioner.run(context.Background(), nil, "volume", "rm", "--force", volume)
|
||||
}()
|
||||
|
||||
cfg := config.Config{Databases: []config.DatabaseConfig{{
|
||||
Name: database,
|
||||
Postgres: &config.PostgresConfig{
|
||||
Image: "postgres:18",
|
||||
Volume: volume,
|
||||
PasswordEnv: envName,
|
||||
},
|
||||
}}}
|
||||
resolved, err := provisioner.Ensure(context.Background(), cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
address := resolved.Databases[0].Upstream
|
||||
waitForAddress(t, address)
|
||||
if err := provisioner.StopDatabase(context.Background(), database); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resolved, err = provisioner.Ensure(context.Background(), cfg)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
waitForAddress(t, resolved.Databases[0].Upstream)
|
||||
}
|
||||
|
||||
func waitForAddress(t *testing.T, address string) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(90 * time.Second)
|
||||
for {
|
||||
connection, err := net.DialTimeout("tcp", address, time.Second)
|
||||
if err == nil {
|
||||
_ = connection.Close()
|
||||
return
|
||||
}
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("PostgreSQL at %s did not accept connections: %v", address, err)
|
||||
}
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user