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

Function testDialError

driver_test.go:2012–2027  ·  view source on GitHub ↗
(t *testing.T, dialErr error, expectErr error)

Source from the content-addressed store, hash-verified

2010}
2011
2012func testDialError(t *testing.T, dialErr error, expectErr error) {
2013 RegisterDialContext("mydial", func(ctx context.Context, addr string) (net.Conn, error) {
2014 return nil, dialErr
2015 })
2016
2017 db, err := sql.Open(driverNameTest, fmt.Sprintf("%s:%s@mydial(%s)/%s?timeout=30s", user, pass, addr, dbname))
2018 if err != nil {
2019 t.Fatalf("error connecting: %s", err.Error())
2020 }
2021 defer db.Close()
2022
2023 _, err = db.Exec("DO 1")
2024 if err != expectErr {
2025 t.Fatalf("was expecting %s. Got: %s", dialErr, err)
2026 }
2027}
2028
2029func TestDialUnknownError(t *testing.T) {
2030 testErr := fmt.Errorf("test")

Callers 3

TestDialUnknownErrorFunction · 0.85
TestDialTemporaryNetErrFunction · 0.85

Calls 5

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

Tested by

no test coverage detected