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

Function TestUnixSocketConnection

database/mysql/database_test.go:13–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestUnixSocketConnection(t *testing.T) {
14 sock := testutil.StartDummyUnixSocket(t, "mysql-socket-test", "mysql.sock")
15 defer sock.Close()
16
17 config := database.Config{
18 DbName: "testdb",
19 User: "testuser",
20 Password: "testpass",
21 Socket: sock.Path,
22 }
23
24 db, err := NewDatabase(config)
25 if err != nil {
26 t.Fatalf("NewDatabase failed: %v", err)
27 }
28 defer db.Close()
29
30 err = db.DB().Ping()
31 if err == nil {
32 t.Fatal("expected connection to fail with protocol error")
33 }
34
35 // "connection refused" means socket path was not used (fell back to TCP).
36 // Any other error (e.g., "malformed packet") indicates the socket was used.
37 if strings.Contains(err.Error(), "connection refused") {
38 t.Errorf("expected socket to be used, got: %v", err)
39 }
40}

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