@@ -80,10 +80,10 @@ func mustQuery(t *testing.T, db *sql.DB, query string, args ...interface{}) (row
80
80
return
81
81
}
82
82
83
- func mustSetCharset (t * testing.T , charsetParam , expected string ) {
83
+ func mustSetCharset (t * testing.T , charsetParam , expected string ) error {
84
84
db , err := sql .Open ("mysql" , strings .Replace (dsn , charset , charsetParam , 1 ))
85
85
if err != nil {
86
- t . Fatalf ( "Error connecting: %v" , err )
86
+ return err
87
87
}
88
88
89
89
rows := mustQuery (t , db , ("SELECT @@character_set_connection" ))
@@ -107,7 +107,9 @@ func TestCharset(t *testing.T) {
107
107
}
108
108
109
109
// 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
+ }
111
113
}
112
114
113
115
func TestFallbackCharset (t * testing.T ) {
@@ -117,14 +119,22 @@ func TestFallbackCharset(t *testing.T) {
117
119
}
118
120
119
121
// 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
+ }
121
125
122
126
// when the first charset is valid, use it
123
127
charsets := []string {"ascii" , "utf8" }
124
128
for i := range charsets {
125
129
expected := charsets [i ]
126
130
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" )
128
138
}
129
139
}
130
140
0 commit comments