| 248 | } |
| 249 | |
| 250 | func TestDSNTLSConfig(t *testing.T) { |
| 251 | expectedServerName := "example.com" |
| 252 | dsn := "tcp(example.com:1234)/?tls=true" |
| 253 | |
| 254 | cfg, err := ParseDSN(dsn) |
| 255 | if err != nil { |
| 256 | t.Error(err.Error()) |
| 257 | } |
| 258 | if cfg.TLS == nil { |
| 259 | t.Error("cfg.tls should not be nil") |
| 260 | } |
| 261 | if cfg.TLS.ServerName != expectedServerName { |
| 262 | t.Errorf("cfg.tls.ServerName should be %q, got %q (host with port)", expectedServerName, cfg.TLS.ServerName) |
| 263 | } |
| 264 | |
| 265 | dsn = "tcp(example.com)/?tls=true" |
| 266 | cfg, err = ParseDSN(dsn) |
| 267 | if err != nil { |
| 268 | t.Error(err.Error()) |
| 269 | } |
| 270 | if cfg.TLS == nil { |
| 271 | t.Error("cfg.tls should not be nil") |
| 272 | } |
| 273 | if cfg.TLS.ServerName != expectedServerName { |
| 274 | t.Errorf("cfg.tls.ServerName should be %q, got %q (host without port)", expectedServerName, cfg.TLS.ServerName) |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | func TestDSNWithCustomTLSQueryEscape(t *testing.T) { |
| 279 | const configKey = "&%!:" |