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

Function FuzzFormatDSN

dsn_fuzz_test.go:10–46  ·  view source on GitHub ↗
(f *testing.F)

Source from the content-addressed store, hash-verified

8)
9
10func FuzzFormatDSN(f *testing.F) {
11 for _, test := range testDSNs { // See dsn_test.go
12 f.Add(test.in)
13 }
14
15 f.Fuzz(func(t *testing.T, dsn1 string) {
16 // Do not waste resources
17 if len(dsn1) > 1000 {
18 t.Skip("ignore: too long")
19 }
20
21 cfg1, err := ParseDSN(dsn1)
22 if err != nil {
23 t.Skipf("invalid DSN: %v", err)
24 }
25
26 dsn2 := cfg1.FormatDSN()
27 if dsn2 == dsn1 {
28 return
29 }
30
31 // Skip known cases of bad config that are not strictly checked by ParseDSN
32 if _, _, err := net.SplitHostPort(cfg1.Addr); err != nil {
33 t.Skipf("invalid addr %q: %v", cfg1.Addr, err)
34 }
35
36 cfg2, err := ParseDSN(dsn2)
37 if err != nil {
38 t.Fatalf("%q rewritten as %q: %v", dsn1, dsn2, err)
39 }
40
41 dsn3 := cfg2.FormatDSN()
42 if dsn3 != dsn2 {
43 t.Errorf("%q rewritten as %q", dsn2, dsn3)
44 }
45 })
46}

Callers

nothing calls this directly

Calls 2

ParseDSNFunction · 0.85
FormatDSNMethod · 0.80

Tested by

no test coverage detected