@@ -84,7 +84,7 @@ func mustQuery(t *testing.T, db *sql.DB, query string, args ...interface{}) (row
8484func mustSetCharset (t * testing.T , charsetParam , expected string ) {
8585 db , err := sql .Open ("mysql" , strings .Replace (dsn , charset , charsetParam , 1 ))
8686 if err != nil {
87- t .Fatalf ("Error connecting : %v" , err )
87+ t .Fatalf ("Error on Open : %v" , err )
8888 }
8989
9090 rows := mustQuery (t , db , ("SELECT @@character_set_connection" ))
@@ -98,7 +98,6 @@ func mustSetCharset(t *testing.T, charsetParam, expected string) {
9898 if got != expected {
9999 t .Fatalf ("Expected connection charset %s but got %s" , expected , got )
100100 }
101- db .Close ()
102101}
103102
104103func TestCharset (t * testing.T ) {
@@ -111,6 +110,16 @@ func TestCharset(t *testing.T) {
111110 mustSetCharset (t , "charset=ascii" , "ascii" )
112111}
113112
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+
114123func TestFallbackCharset (t * testing.T ) {
115124 if ! getEnv () {
116125 t .Logf ("MySQL-Server not running on %s. Skipping TestFallbackCharset" , netAddr )
0 commit comments