utils_go18_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2017 The Go-MySQL-Driver Authors. All rights reserved.
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public
  6. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  7. // You can obtain one at http://mozilla.org/MPL/2.0/.
  8. // +build go1.8
  9. package mysql
  10. import (
  11. "database/sql"
  12. "database/sql/driver"
  13. "testing"
  14. )
  15. func TestIsolationLevelMapping(t *testing.T) {
  16. data := []struct {
  17. level driver.IsolationLevel
  18. expected string
  19. }{
  20. {
  21. level: driver.IsolationLevel(sql.LevelReadCommitted),
  22. expected: "READ COMMITTED",
  23. },
  24. {
  25. level: driver.IsolationLevel(sql.LevelRepeatableRead),
  26. expected: "REPEATABLE READ",
  27. },
  28. {
  29. level: driver.IsolationLevel(sql.LevelReadUncommitted),
  30. expected: "READ UNCOMMITTED",
  31. },
  32. {
  33. level: driver.IsolationLevel(sql.LevelSerializable),
  34. expected: "SERIALIZABLE",
  35. },
  36. }
  37. for i, td := range data {
  38. if actual, err := mapIsolationLevel(td.level); actual != td.expected || err != nil {
  39. t.Fatal(i, td.expected, actual, err)
  40. }
  41. }
  42. // check unsupported mapping
  43. if actual, err := mapIsolationLevel(driver.IsolationLevel(sql.LevelLinearizable)); actual != "" || err == nil {
  44. t.Fatal("Expected error on unsupported isolation level")
  45. }
  46. }