MCPcopy
hub / github.com/sqldef/sqldef / TestUnixSocketConnection

Function TestUnixSocketConnection

database/postgres/database_test.go:20–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestUnixSocketConnection(t *testing.T) {
21 // PostgreSQL expects socket files named .s.PGSQL.<port> in the directory
22 sock := testutil.StartDummyUnixSocket(t, "postgres-socket-test", ".s.PGSQL.5432")
23 defer sock.Close()
24
25 config := database.Config{
26 DbName: "testdb",
27 User: "testuser",
28 Password: "testpass",
29 Socket: sock.Dir,
30 Port: 5432,
31 }
32
33 db, err := NewDatabase(config)
34 if err != nil {
35 t.Fatalf("NewDatabase failed: %v", err)
36 }
37 defer db.Close()
38
39 err = db.DB().Ping()
40 if err == nil {
41 t.Fatal("expected connection to fail with protocol error")
42 }
43
44 // "connection refused" means socket path was not used (fell back to TCP).
45 // Any other error (e.g., protocol error) indicates the socket was used.
46 if strings.Contains(err.Error(), "connection refused") {
47 t.Errorf("expected socket to be used, got: %v", err)
48 }
49}
50
51// TestExtensionOIDCollisionByInjectedDependency verifies that ExportDDLs correctly
52// handles OID collisions between user objects and extension objects.

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
DBMethod · 0.95
StartDummyUnixSocketFunction · 0.92
NewDatabaseFunction · 0.70
FatalfMethod · 0.65
FatalMethod · 0.65
ErrorMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected