MCPcopy
hub / github.com/gourouting/singo / TestDatabaseDSNRejectsReservedCharacters

Function TestDatabaseDSNRejectsReservedCharacters

conf/conf_test.go:182–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

180}
181
182func TestDatabaseDSNRejectsReservedCharacters(t *testing.T) {
183 tests := []struct {
184 name string
185 values map[string]string
186 want string
187 }{
188 {
189 name: "user colon",
190 values: map[string]string{
191 "DB_USER": "app:user",
192 "DB_NAME": "singo",
193 },
194 want: "DB_USER",
195 },
196 {
197 name: "database slash",
198 values: map[string]string{
199 "DB_USER": "app",
200 "DB_NAME": "singo/test",
201 },
202 want: "DB_NAME",
203 },
204 }
205
206 for _, tt := range tests {
207 t.Run(tt.name, func(t *testing.T) {
208 setDBEnv(t, tt.values)
209
210 dsn, err := DatabaseDSN()
211 if err == nil {
212 t.Fatal("expected reserved character error")
213 }
214 if dsn != "" {
215 t.Fatalf("expected empty DSN, got %q", dsn)
216 }
217 if !strings.Contains(err.Error(), tt.want) {
218 t.Fatalf("expected error to mention %s, got %q", tt.want, err.Error())
219 }
220 })
221 }
222}

Callers

nothing calls this directly

Calls 3

setDBEnvFunction · 0.85
DatabaseDSNFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected