| 125 | } |
| 126 | |
| 127 | func TestDSNReformat(t *testing.T) { |
| 128 | for i, tst := range testDSNs { |
| 129 | t.Run(tst.in, func(t *testing.T) { |
| 130 | dsn1 := tst.in |
| 131 | cfg1, err := ParseDSN(dsn1) |
| 132 | if err != nil { |
| 133 | t.Error(err.Error()) |
| 134 | return |
| 135 | } |
| 136 | cfg1.TLS = nil // pointer not static |
| 137 | res1 := fmt.Sprintf("%+v", cfg1) |
| 138 | |
| 139 | dsn2 := cfg1.FormatDSN() |
| 140 | if dsn2 != dsn1 { |
| 141 | // Just log |
| 142 | t.Logf("%d. %q reformatted as %q", i, dsn1, dsn2) |
| 143 | } |
| 144 | |
| 145 | cfg2, err := ParseDSN(dsn2) |
| 146 | if err != nil { |
| 147 | t.Error(err.Error()) |
| 148 | return |
| 149 | } |
| 150 | cfg2.TLS = nil // pointer not static |
| 151 | res2 := fmt.Sprintf("%+v", cfg2) |
| 152 | |
| 153 | if res1 != res2 { |
| 154 | t.Errorf("%d. %q does not match %q", i, res2, res1) |
| 155 | } |
| 156 | |
| 157 | dsn3 := cfg2.FormatDSN() |
| 158 | if dsn3 != dsn2 { |
| 159 | t.Errorf("%d. %q does not match %q", i, dsn2, dsn3) |
| 160 | } |
| 161 | }) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | func TestDSNServerPubKey(t *testing.T) { |
| 166 | baseDSN := "User:password@tcp(localhost:5555)/dbname?serverPubKey=" |