@@ -84,7 +84,7 @@ func mustQuery(t *testing.T, db *sql.DB, query string, args ...interface{}) (row
84
84
func mustSetCharset (t * testing.T , charsetParam , expected string ) {
85
85
db , err := sql .Open ("mysql" , strings .Replace (dsn , charset , charsetParam , 1 ))
86
86
if err != nil {
87
- t .Fatalf ("Error connecting : %v" , err )
87
+ t .Fatalf ("Error on Open : %v" , err )
88
88
}
89
89
90
90
rows := mustQuery (t , db , ("SELECT @@character_set_connection" ))
@@ -98,7 +98,6 @@ func mustSetCharset(t *testing.T, charsetParam, expected string) {
98
98
if got != expected {
99
99
t .Fatalf ("Expected connection charset %s but got %s" , expected , got )
100
100
}
101
- db .Close ()
102
101
}
103
102
104
103
func TestCharset (t * testing.T ) {
@@ -111,6 +110,16 @@ func TestCharset(t *testing.T) {
111
110
mustSetCharset (t , "charset=ascii" , "ascii" )
112
111
}
113
112
113
+ func TestFailingCharset (t * testing.T ) {
114
+ db , err := sql .Open ("mysql" , strings .Replace (dsn , charset , "charset=none" , 1 ))
115
+ // run query to really establish connection...
116
+ _ , err = db .Exec ("SELECT 1" )
117
+ if err == nil {
118
+ db .Close ()
119
+ t .Fatalf ("Connection must not succeed without a valid charset" )
120
+ }
121
+ }
122
+
114
123
func TestFallbackCharset (t * testing.T ) {
115
124
if ! getEnv () {
116
125
t .Logf ("MySQL-Server not running on %s. Skipping TestFallbackCharset" , netAddr )
0 commit comments