1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-30 09:06:45 +02:00
authboss/defaults/logger_test.go
Aaron L 27010d9fe4 Abstract logger and error handling
- Replace the old logging mechanisms with a leveled one. This is
  important as authboss needs to start saying a lot more about what's
  happening in the Info log, which will end up like Debug but that's
  okay.
- Replace the error handling mechanisms with something different. This
  allows people to define their own error handlers.
2018-02-02 12:11:47 -08:00

27 lines
555 B
Go

package defaults
import (
"bytes"
"regexp"
"testing"
"github.com/davecgh/go-spew/spew"
)
func TestLogger(t *testing.T) {
t.Parallel()
b := &bytes.Buffer{}
logger := NewLogger(b)
logger.Info("hello")
logger.Error("world")
rgxTimestamp := `[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z`
rgx := regexp.MustCompile(rgxTimestamp + ` \[INFO\]: hello\n` + rgxTimestamp + ` \[EROR\]: world\n`)
if !rgx.Match(b.Bytes()) {
t.Errorf("output from log file did not match regex:\n%s\n%v", b.String(), b.Bytes())
spew.Dump(b.Bytes())
}
}