Skip to content

Commit 19ce774

Browse files
committed
test for error if no charset could be set
1 parent 7da9257 commit 19ce774

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

driver_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ func mustQuery(t *testing.T, db *sql.DB, query string, args ...interface{}) (row
8080
return
8181
}
8282

83-
func mustSetCharset(t *testing.T, charsetParam, expected string) {
83+
func mustSetCharset(t *testing.T, charsetParam, expected string) error {
8484
db, err := sql.Open("mysql", strings.Replace(dsn, charset, charsetParam, 1))
8585
if err != nil {
86-
t.Fatalf("Error connecting: %v", err)
86+
return err
8787
}
8888

8989
rows := mustQuery(t, db, ("SELECT @@character_set_connection"))
@@ -107,7 +107,9 @@ func TestCharset(t *testing.T) {
107107
}
108108

109109
// non utf8 test
110-
mustSetCharset(t, "charset=ascii", "ascii")
110+
if err := mustSetCharset(t, "charset=ascii", "ascii"); err != nil {
111+
t.Fatalf("Error connecting: %v", err)
112+
}
111113
}
112114

113115
func TestFallbackCharset(t *testing.T) {
@@ -117,14 +119,22 @@ func TestFallbackCharset(t *testing.T) {
117119
}
118120

119121
// when the first charset is invalid, use the second
120-
mustSetCharset(t, "charset=none,utf8", "utf8")
122+
if err := mustSetCharset(t, "charset=none,utf8", "utf8")
123+
t.Fatalf("Error connecting: %v", err)
124+
}
121125

122126
// when the first charset is valid, use it
123127
charsets := []string{"ascii", "utf8"}
124128
for i := range charsets {
125129
expected := charsets[i]
126130
other := charsets[1-i]
127-
mustSetCharset(t, "charset="+expected+","+other, expected)
131+
if err = mustSetCharset(t, "charset="+expected+","+other, expected); err != nil {
132+
t.Fatalf("Error connecting: %v", err)
133+
}
134+
}
135+
136+
if err = mustSetCharset(t, "charset=none1,none2", "utf8"); err == nil {
137+
t.Fatalf("Must throw an error if no charsets are supported")
128138
}
129139
}
130140

0 commit comments

Comments
 (0)