MCPcopy
hub / github.com/go-sql-driver/mysql / TestCustomDial

Function TestCustomDial

driver_test.go:2045–2065  ·  view source on GitHub ↗

Tests custom dial functions

(t *testing.T)

Source from the content-addressed store, hash-verified

2043
2044// Tests custom dial functions
2045func TestCustomDial(t *testing.T) {
2046 if !available {
2047 t.Skipf("MySQL server not running on %s", netAddr)
2048 }
2049
2050 // our custom dial function which just wraps net.Dial here
2051 RegisterDialContext("mydial", func(ctx context.Context, addr string) (net.Conn, error) {
2052 var d net.Dialer
2053 return d.DialContext(ctx, prot, addr)
2054 })
2055
2056 db, err := sql.Open(driverNameTest, fmt.Sprintf("%s:%s@mydial(%s)/%s?timeout=30s", user, pass, addr, dbname))
2057 if err != nil {
2058 t.Fatalf("error connecting: %s", err.Error())
2059 }
2060 defer db.Close()
2061
2062 if _, err = db.Exec("DO 1"); err != nil {
2063 t.Fatalf("connection failed: %s", err.Error())
2064 }
2065}
2066
2067func TestBeforeConnect(t *testing.T) {
2068 if !available {

Callers

nothing calls this directly

Calls 5

RegisterDialContextFunction · 0.85
OpenMethod · 0.80
ErrorMethod · 0.45
CloseMethod · 0.45
ExecMethod · 0.45

Tested by

no test coverage detected