test for change output

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-11-10 12:23:56 +03:00
parent d0ca101c7c
commit f4c8a9d18c

View File

@ -1,6 +1,7 @@
package zerolog
import (
"bytes"
"context"
"errors"
"os"
@ -11,6 +12,18 @@ import (
"go.unistack.org/micro/v3/logger"
)
func TestOutput(t *testing.T) {
buf := bytes.NewBuffer(nil)
l := NewLogger(logger.WithOutput(buf))
if err := l.Init(); err != nil {
t.Fatal(err)
}
l.Infof(context.TODO(), "test logger name: %s", "name")
if !bytes.Contains(buf.Bytes(), []byte(`test logger name`)) {
t.Fatalf("log not redirected: %s", buf.Bytes())
}
}
func TestName(t *testing.T) {
l := NewLogger()
l.Init()