aboutsummaryrefslogtreecommitdiff
path: root/logger/logger_test.go
diff options
context:
space:
mode:
authorn-peugnet <n.peugnet@free.fr>2021-09-15 01:06:38 +0200
committern-peugnet <n.peugnet@free.fr>2021-09-15 01:17:43 +0200
commit6b64e08ed77e7752af307b82bbe1aa14200f269a (patch)
tree9f761c8d74cd32da98ac4fbadfcbf875eae98b7c /logger/logger_test.go
parentf21468b03329a3751a50eb829e07271d23ce4720 (diff)
downloaddna-backup-6b64e08ed77e7752af307b82bbe1aa14200f269a.tar.gz
dna-backup-6b64e08ed77e7752af307b82bbe1aa14200f269a.zip
logger fixes and better tests
Diffstat (limited to 'logger/logger_test.go')
-rw-r--r--logger/logger_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/logger/logger_test.go b/logger/logger_test.go
index ce708bb..4d07d8c 100644
--- a/logger/logger_test.go
+++ b/logger/logger_test.go
@@ -3,7 +3,9 @@ package logger
import (
"bufio"
"bytes"
+ "log"
"os"
+ "path/filepath"
"reflect"
"strings"
"testing"
@@ -85,3 +87,60 @@ func TestInit(t *testing.T) {
}
}
}
+
+func TestLevel(t *testing.T) {
+ initialize()
+ var buf bytes.Buffer
+ Init(1)
+ SetOutput(&buf)
+
+ Infof("info %d", sInfo)
+ Warningf("warning %d", sWarning)
+ Errorf("error %d", sError)
+ s := buf.String()
+ if strings.Contains(s, "info") {
+ t.Errorf("log output %q should not contain: info", s)
+ }
+ if strings.Contains(s, "warning") {
+ t.Errorf("log output %q should not contain: warning", s)
+ }
+ if !strings.Contains(s, "error") {
+ t.Errorf("log output %q should contain: error", s)
+ }
+}
+
+func TestFlags(t *testing.T) {
+ initialize()
+ l := Init(3)
+ SetFlags(log.Llongfile)
+ var buf bytes.Buffer
+ SetOutput(&buf)
+ l.Infof("info %d", sInfo)
+ s := buf.String()
+ if !strings.Contains(s, "info 0") {
+ t.Errorf("log output %q should contain: info 0", s)
+ }
+ path := filepath.Join("logger", "logger_test.go")
+ if !strings.Contains(s, path) {
+ t.Errorf("log output %q should contain: %s", s, path)
+ }
+
+ // bonus for coverage
+ l.Warning("warning")
+ l.Warningf("warning %d", sWarning)
+ l.Error("error")
+ l.Errorf("error %d", sError)
+ s = buf.String()
+ if !strings.Contains(s, "warning") {
+ t.Errorf("log output %q should contain: warning", s)
+ }
+ if !strings.Contains(s, "warning 1") {
+ t.Errorf("log output %q should contain: warning 1", s)
+ }
+ if !strings.Contains(s, "error") {
+ t.Errorf("log output %q should contain: error", s)
+ }
+ if !strings.Contains(s, "error 2") {
+ t.Errorf("log output %q should contain: error 2", s)
+ }
+}