errors_test.go 768 B

123456789101112131415161718192021222324252627282930
  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 TestSetLogger(t *testing.T) {
  15. previous := errLog
  16. defer func() {
  17. errLog = previous
  18. }()
  19. const expected = "prefix: test\n"
  20. buffer := bytes.NewBuffer(make([]byte, 0, 64))
  21. logger := log.New(buffer, "prefix: ", 0)
  22. SetLogger(logger)
  23. errLog.Print("test")
  24. if actual := buffer.String(); actual != expected {
  25. t.Errorf("expected %q, got %q", expected, actual)
  26. }
  27. }