MCPcopy
hub / github.com/go-sql-driver/mysql / TestCloneConfig

Function TestCloneConfig

dsn_test.go:348–386  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

346}
347
348func 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
388func TestNormalizeTLSConfig(t *testing.T) {
389 tt := []struct {

Callers

nothing calls this directly

Calls 5

RegisterServerPubKeyFunction · 0.85
DeregisterServerPubKeyFunction · 0.85
ParseDSNFunction · 0.85
CloneMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected