(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func 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 | } |
nothing calls this directly
no test coverage detected