Tests custom dial functions
(t *testing.T)
| 2043 | |
| 2044 | // Tests custom dial functions |
| 2045 | func 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 | |
| 2067 | func TestBeforeConnect(t *testing.T) { |
| 2068 | if !available { |
nothing calls this directly
no test coverage detected