diff options
author | root <sina@snix.ir> | 2022-05-27 13:13:53 +0000 |
---|---|---|
committer | root <sina@snix.ir> | 2022-05-27 13:13:53 +0000 |
commit | 937c561db4b25a1becdc81701511fafc67b90389 (patch) | |
tree | 17e5d4c692ec4ab3c8b0deb0072d5784cc4be084 /connector_test.go |
Diffstat (limited to 'connector_test.go')
-rw-r--r-- | connector_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/connector_test.go b/connector_test.go new file mode 100644 index 0000000..360e7c5 --- /dev/null +++ b/connector_test.go @@ -0,0 +1,30 @@ +package mariadb + +import ( + "context" + "net" + "testing" + "time" +) + +func TestConnectorReturnsTimeout(t *testing.T) { + connector := &connector{&Config{ + Net: "tcp", + Addr: "1.1.1.1:1234", + Timeout: 10 * time.Millisecond, + }} + + _, err := connector.Connect(context.Background()) + if err == nil { + t.Fatal("error expected") + } + + if nerr, ok := err.(*net.OpError); ok { + expected := "dial tcp 1.1.1.1:1234: i/o timeout" + if nerr.Error() != expected { + t.Fatalf("expected %q, got %q", expected, nerr.Error()) + } + } else { + t.Fatalf("expected %T, got %T", nerr, err) + } +} |