(t *testing.T)
| 207 | } |
| 208 | |
| 209 | func TestDSNWithCustomTLS(t *testing.T) { |
| 210 | baseDSN := "User:password@tcp(localhost:5555)/dbname?tls=" |
| 211 | tlsCfg := tls.Config{} |
| 212 | |
| 213 | RegisterTLSConfig("utils_test", &tlsCfg) |
| 214 | defer DeregisterTLSConfig("utils_test") |
| 215 | |
| 216 | // Custom TLS is missing |
| 217 | tst := baseDSN + "invalid_tls" |
| 218 | cfg, err := ParseDSN(tst) |
| 219 | if err == nil { |
| 220 | t.Errorf("invalid custom TLS in DSN (%s) but did not error. Got config: %#v", tst, cfg) |
| 221 | } |
| 222 | |
| 223 | tst = baseDSN + "utils_test" |
| 224 | |
| 225 | // Custom TLS with a server name |
| 226 | name := "foohost" |
| 227 | tlsCfg.ServerName = name |
| 228 | cfg, err = ParseDSN(tst) |
| 229 | |
| 230 | if err != nil { |
| 231 | t.Error(err.Error()) |
| 232 | } else if cfg.TLS.ServerName != name { |
| 233 | t.Errorf("did not get the correct TLS ServerName (%s) parsing DSN (%s).", name, tst) |
| 234 | } |
| 235 | |
| 236 | // Custom TLS without a server name |
| 237 | name = "localhost" |
| 238 | tlsCfg.ServerName = "" |
| 239 | cfg, err = ParseDSN(tst) |
| 240 | |
| 241 | if err != nil { |
| 242 | t.Error(err.Error()) |
| 243 | } else if cfg.TLS.ServerName != name { |
| 244 | t.Errorf("did not get the correct ServerName (%s) parsing DSN (%s).", name, tst) |
| 245 | } else if tlsCfg.ServerName != "" { |
| 246 | t.Errorf("tlsCfg was mutated ServerName (%s) should be empty parsing DSN (%s).", name, tst) |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | func TestDSNTLSConfig(t *testing.T) { |
| 251 | expectedServerName := "example.com" |
nothing calls this directly
no test coverage detected