82 lines
1.3 KiB
Go
82 lines
1.3 KiB
Go
package logb
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestSet(t *testing.T) {
|
|
Set()
|
|
if level != INFO {
|
|
t.Error(level, INFO)
|
|
}
|
|
Set(VERBOSE)
|
|
if level != VERBOSE {
|
|
t.Error(level, VERBOSE)
|
|
}
|
|
}
|
|
|
|
func TestLogf(t *testing.T) {
|
|
cases := map[string]struct {
|
|
foo func(...interface{})
|
|
in []interface{}
|
|
out string
|
|
}{
|
|
"info empty": {
|
|
foo: Info,
|
|
in: []interface{}{},
|
|
out: "[INF] ",
|
|
},
|
|
"info args": {
|
|
foo: Info,
|
|
in: []interface{}{"hello", "info"},
|
|
out: "[INF] hello info",
|
|
},
|
|
"debug empty": {
|
|
foo: Debug,
|
|
in: []interface{}{},
|
|
out: "[DEB] ",
|
|
},
|
|
"debug args": {
|
|
foo: Debug,
|
|
in: []interface{}{"hello", "debug"},
|
|
out: "[DEB] hello debug",
|
|
},
|
|
"error empty": {
|
|
foo: Error,
|
|
in: []interface{}{},
|
|
out: "[ERR] ",
|
|
},
|
|
"error args": {
|
|
foo: Error,
|
|
in: []interface{}{"hello", "error"},
|
|
out: "[ERR] hello error",
|
|
},
|
|
"verbose empty": {
|
|
foo: Verbose,
|
|
in: []interface{}{},
|
|
out: "[VER] ",
|
|
},
|
|
"verbose args": {
|
|
foo: Verbose,
|
|
in: []interface{}{"hello", "verbose"},
|
|
out: "[VER] hello verbose",
|
|
},
|
|
}
|
|
|
|
for i, c := range cases {
|
|
w := bytes.NewBuffer(nil)
|
|
SetWriter(w)
|
|
Set(VERBOSE)
|
|
c.foo(c.in...)
|
|
out := fmt.Sprintf("%s", w.Bytes())
|
|
if out != c.out+"\n" {
|
|
t.Errorf("[%s]: %v => %q, want %q", i, c.in, out, c.out)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLog(t *testing.T) {
|
|
}
|