connector_test.go 578 B

123456789101112131415161718192021222324252627282930
  1. package mysql
  2. import (
  3. "context"
  4. "net"
  5. "testing"
  6. "time"
  7. )
  8. func TestConnectorReturnsTimeout(t *testing.T) {
  9. connector := &connector{&Config{
  10. Net: "tcp",
  11. Addr: "1.1.1.1:1234",
  12. Timeout: 10 * time.Millisecond,
  13. }}
  14. _, err := connector.Connect(context.Background())
  15. if err == nil {
  16. t.Fatal("error expected")
  17. }
  18. if nerr, ok := err.(*net.OpError); ok {
  19. expected := "dial tcp 1.1.1.1:1234: i/o timeout"
  20. if nerr.Error() != expected {
  21. t.Fatalf("expected %q, got %q", expected, nerr.Error())
  22. }
  23. } else {
  24. t.Fatalf("expected %T, got %T", nerr, err)
  25. }
  26. }