(t *testing.T)
| 346 | } |
| 347 | |
| 348 | func TestCloneConfig(t *testing.T) { |
| 349 | RegisterServerPubKey("testKey", testPubKeyRSA) |
| 350 | defer DeregisterServerPubKey("testKey") |
| 351 | |
| 352 | expectedServerName := "example.com" |
| 353 | dsn := "tcp(example.com:1234)/?tls=true&foobar=baz&serverPubKey=testKey" |
| 354 | cfg, err := ParseDSN(dsn) |
| 355 | if err != nil { |
| 356 | t.Fatal(err.Error()) |
| 357 | } |
| 358 | |
| 359 | cfg2 := cfg.Clone() |
| 360 | if cfg == cfg2 { |
| 361 | t.Errorf("Config.Clone did not create a separate config struct") |
| 362 | } |
| 363 | |
| 364 | if cfg2.TLS.ServerName != expectedServerName { |
| 365 | t.Errorf("cfg.tls.ServerName should be %q, got %q (host with port)", expectedServerName, cfg.TLS.ServerName) |
| 366 | } |
| 367 | |
| 368 | cfg2.TLS.ServerName = "example2.com" |
| 369 | if cfg.TLS.ServerName == cfg2.TLS.ServerName { |
| 370 | t.Errorf("changed cfg.tls.Server name should not propagate to original Config") |
| 371 | } |
| 372 | |
| 373 | if _, ok := cfg2.Params["foobar"]; !ok { |
| 374 | t.Errorf("cloned Config is missing custom params") |
| 375 | } |
| 376 | |
| 377 | delete(cfg2.Params, "foobar") |
| 378 | |
| 379 | if _, ok := cfg.Params["foobar"]; !ok { |
| 380 | t.Errorf("custom params in cloned Config should not propagate to original Config") |
| 381 | } |
| 382 | |
| 383 | if !reflect.DeepEqual(cfg.pubKey, cfg2.pubKey) { |
| 384 | t.Errorf("public key in Config should be identical") |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | func TestNormalizeTLSConfig(t *testing.T) { |
| 389 | tt := []struct { |
nothing calls this directly
no test coverage detected