| 1559 | } |
| 1560 | |
| 1561 | func TestCharset(t *testing.T) { |
| 1562 | if !available { |
| 1563 | t.Skipf("MySQL server not running on %s", netAddr) |
| 1564 | } |
| 1565 | |
| 1566 | mustSetCharset := func(charsetParam, expected string) { |
| 1567 | runTests(t, dsn+"&"+charsetParam, func(dbt *DBTest) { |
| 1568 | rows := dbt.mustQuery("SELECT @@character_set_connection") |
| 1569 | defer rows.Close() |
| 1570 | |
| 1571 | if !rows.Next() { |
| 1572 | dbt.Fatalf("error getting connection charset: %s", rows.Err()) |
| 1573 | } |
| 1574 | |
| 1575 | var got string |
| 1576 | rows.Scan(&got) |
| 1577 | |
| 1578 | if got != expected { |
| 1579 | dbt.Fatalf("expected connection charset %s but got %s", expected, got) |
| 1580 | } |
| 1581 | }) |
| 1582 | } |
| 1583 | |
| 1584 | // non utf8 test |
| 1585 | mustSetCharset("charset=ascii", "ascii") |
| 1586 | |
| 1587 | // when the first charset is invalid, use the second |
| 1588 | mustSetCharset("charset=none,utf8mb4", "utf8mb4") |
| 1589 | |
| 1590 | // when the first charset is valid, use it |
| 1591 | mustSetCharset("charset=ascii,utf8mb4", "ascii") |
| 1592 | mustSetCharset("charset=utf8mb4,ascii", "utf8mb4") |
| 1593 | } |
| 1594 | |
| 1595 | func TestFailingCharset(t *testing.T) { |
| 1596 | runTestsParallel(t, dsn+"&charset=none", func(dbt *DBTest, _ string) { |