test for change output

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

View File

@ -1,6 +1,7 @@
package logrus
import (
"bytes"
"context"
"errors"
"os"
@ -10,6 +11,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()
if err := l.Init(); err != nil {