sql_test.go 716 B

123456789101112131415161718192021
  1. package tidb
  2. import "testing"
  3. func TestParseDSNAddrr(t *testing.T) {
  4. dsn := "u:p@tcp(127.0.0.1:3306)/db?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
  5. addr := parseDSNAddr(dsn)
  6. if addr != "127.0.0.1:3306" {
  7. t.Errorf("expect 127.0.0.1:3306 got: %s", addr)
  8. }
  9. }
  10. func TestGenDSN(t *testing.T) {
  11. dsn := "u:p@tcp(127.0.0.1:3306)/db?loc=Local&parseTime=true&readTimeout=5s&timeout=5s&writeTimeout=5s&charset=utf8mb4"
  12. addr := "127.0.0.2:3308"
  13. expect := "u:p@tcp(127.0.0.2:3308)/db?loc=Local&parseTime=true&readTimeout=5s&timeout=5s&writeTimeout=5s&charset=utf8mb4"
  14. newdsn := genDSN(dsn, addr)
  15. if newdsn != expect {
  16. t.Errorf("expect %s got: %s", expect, newdsn)
  17. }
  18. }