github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/database/mysql/errors_test.go (about) 1 // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 // 3 // Copyright 2013 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 package mysql 10 11 import ( 12 "bytes" 13 "log" 14 "testing" 15 ) 16 17 func TestErrorsSetLogger(t *testing.T) { 18 previous := errLog 19 defer func() { 20 errLog = previous 21 }() 22 23 // set up logger 24 const expected = "prefix: test\n" 25 buffer := bytes.NewBuffer(make([]byte, 0, 64)) 26 logger := log.New(buffer, "prefix: ", 0) 27 28 // print 29 SetLogger(logger) 30 errLog.Print("test") 31 32 // check result 33 if actual := buffer.String(); actual != expected { 34 t.Errorf("expected %q, got %q", expected, actual) 35 } 36 } 37 38 func TestErrorsStrictIgnoreNotes(t *testing.T) { 39 runTests(t, dsn+"&sql_notes=false", func(dbt *DBTest) { 40 dbt.mustExec("DROP TABLE IF EXISTS does_not_exist") 41 }) 42 }