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

Function TestNormalizeTLSConfig

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

Source from the content-addressed store, hash-verified

386}
387
388func TestNormalizeTLSConfig(t *testing.T) {
389 tt := []struct {
390 tlsConfig string
391 want *tls.Config
392 }{
393 {"", nil},
394 {"false", nil},
395 {"true", &tls.Config{ServerName: "myserver"}},
396 {"skip-verify", &tls.Config{InsecureSkipVerify: true}},
397 {"preferred", &tls.Config{InsecureSkipVerify: true}},
398 {"test_tls_config", &tls.Config{ServerName: "myServerName"}},
399 }
400
401 RegisterTLSConfig("test_tls_config", &tls.Config{ServerName: "myServerName"})
402 defer func() { DeregisterTLSConfig("test_tls_config") }()
403
404 for _, tc := range tt {
405 t.Run(tc.tlsConfig, func(t *testing.T) {
406 cfg := &Config{
407 Addr: "myserver:3306",
408 TLSConfig: tc.tlsConfig,
409 }
410
411 cfg.normalize()
412
413 if cfg.TLS == nil {
414 if tc.want != nil {
415 t.Fatal("wanted a tls config but got nil instead")
416 }
417 return
418 }
419
420 if cfg.TLS.ServerName != tc.want.ServerName {
421 t.Errorf("tls.ServerName doesn't match (want: '%s', got: '%s')",
422 tc.want.ServerName, cfg.TLS.ServerName)
423 }
424 if cfg.TLS.InsecureSkipVerify != tc.want.InsecureSkipVerify {
425 t.Errorf("tls.InsecureSkipVerify doesn't match (want: %T, got :%T)",
426 tc.want.InsecureSkipVerify, cfg.TLS.InsecureSkipVerify)
427 }
428 })
429 }
430}
431
432func BenchmarkParseDSN(b *testing.B) {
433 b.ReportAllocs()

Callers

nothing calls this directly

Calls 3

normalizeMethod · 0.95
RegisterTLSConfigFunction · 0.85
DeregisterTLSConfigFunction · 0.85

Tested by

no test coverage detected