MCPcopy
hub / github.com/go-sql-driver/mysql / TestCharset

Function TestCharset

driver_test.go:1561–1593  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1559}
1560
1561func 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
1595func TestFailingCharset(t *testing.T) {
1596 runTestsParallel(t, dsn+"&charset=none", func(dbt *DBTest, _ string) {

Callers

nothing calls this directly

Calls 5

runTestsFunction · 0.85
mustQueryMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected