errors_test.go 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. package mysql
  9. import (
  10. "bytes"
  11. "log"
  12. "testing"
  13. )
  14. func TestErrorsSetLogger(t *testing.T) {
  15. previous := errLog
  16. defer func() {
  17. errLog = previous
  18. }()
  19. // set up logger
  20. const expected = "prefix: test\n"
  21. buffer := bytes.NewBuffer(make([]byte, 0, 64))
  22. logger := log.New(buffer, "prefix: ", 0)
  23. // print
  24. SetLogger(logger)
  25. errLog.Print("test")
  26. // check result
  27. if actual := buffer.String(); actual != expected {
  28. t.Errorf("expected %q, got %q", expected, actual)
  29. }
  30. }
  31. func TestErrorsStrictIgnoreNotes(t *testing.T) {
  32. runTests(t, dsn+"&sql_notes=false", func(dbt *DBTest) {
  33. dbt.mustExec("DROP TABLE IF EXISTS does_not_exist")
  34. })
  35. }