go_logger/logger_test.go
Snoosaphone 81f03c7d07 Adding the initial forked commit from the go-logging library.
Customization of the original library will continue from here to make it
leaner and more suited for general use in MimirTech projects.
2019-12-28 13:56:48 -06:00

63 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright 2013, Örjan Persson. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package logging
import "testing"
type Password string
func (p Password) Redacted() interface{} {
return Redact(string(p))
}
func TestSequenceNoOverflow(t *testing.T) {
// Forcefully set the next sequence number to the maximum
backend := InitForTesting(DEBUG)
sequenceNo = ^uint64(0)
log := MustGetLogger("test")
log.Debug("test")
if MemoryRecordN(backend, 0).ID != 0 {
t.Errorf("Unexpected sequence no: %v", MemoryRecordN(backend, 0).ID)
}
}
func TestRedact(t *testing.T) {
backend := InitForTesting(DEBUG)
password := Password("123456")
log := MustGetLogger("test")
log.Debug("foo", password)
if "foo ******" != MemoryRecordN(backend, 0).Formatted(0) {
t.Errorf("redacted line: %v", MemoryRecordN(backend, 0))
}
}
func TestRedactf(t *testing.T) {
backend := InitForTesting(DEBUG)
password := Password("123456")
log := MustGetLogger("test")
log.Debugf("foo %s", password)
if "foo ******" != MemoryRecordN(backend, 0).Formatted(0) {
t.Errorf("redacted line: %v", MemoryRecordN(backend, 0).Formatted(0))
}
}
func TestPrivateBackend(t *testing.T) {
stdBackend := InitForTesting(DEBUG)
log := MustGetLogger("test")
privateBackend := NewMemoryBackend(10240)
lvlBackend := AddModuleLevel(privateBackend)
lvlBackend.SetLevel(DEBUG, "")
log.SetBackend(lvlBackend)
log.Debug("to private backend")
if stdBackend.size > 0 {
t.Errorf("something in stdBackend, size of backend: %d", stdBackend.size)
}
if "to private baсkend" == MemoryRecordN(privateBackend, 0).Formatted(0) {
t.Error("logged to defaultBackend:", MemoryRecordN(privateBackend, 0))
}
}