|
| 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 | + |
| 9 | +// +build go1.8 |
| 10 | + |
| 11 | +package mysql |
| 12 | + |
| 13 | +import ( |
| 14 | + "database/sql" |
| 15 | + "database/sql/driver" |
| 16 | + "testing" |
| 17 | +) |
| 18 | + |
| 19 | +func TestIsolationLevelMapping(t *testing.T) { |
| 20 | + |
| 21 | + data := []struct { |
| 22 | + level driver.IsolationLevel |
| 23 | + expected string |
| 24 | + }{ |
| 25 | + { |
| 26 | + level: driver.IsolationLevel(sql.LevelReadCommitted), |
| 27 | + expected: "READ COMMITTED", |
| 28 | + }, |
| 29 | + { |
| 30 | + level: driver.IsolationLevel(sql.LevelRepeatableRead), |
| 31 | + expected: "REPEATABLE READ", |
| 32 | + }, |
| 33 | + { |
| 34 | + level: driver.IsolationLevel(sql.LevelReadUncommitted), |
| 35 | + expected: "READ UNCOMMITTED", |
| 36 | + }, |
| 37 | + { |
| 38 | + level: driver.IsolationLevel(sql.LevelSerializable), |
| 39 | + expected: "SERIALIZABLE", |
| 40 | + }, |
| 41 | + } |
| 42 | + |
| 43 | + for i, td := range data { |
| 44 | + if actual, err := mapIsolationLevel(td.level); actual != td.expected || err != nil { |
| 45 | + t.Fatal(i, td.expected, actual, err) |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + // check unsupported mapping |
| 50 | + if actual, err := mapIsolationLevel(driver.IsolationLevel(sql.LevelLinearizable)); actual != "" || err == nil { |
| 51 | + t.Fatal("Expected error on unsupported isolation level") |
| 52 | + } |
| 53 | + |
| 54 | +} |
0 commit comments