2021-03-14 15:36:00 +08:00
|
|
|
package log
|
|
|
|
|
2021-10-21 17:39:33 +08:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
)
|
2021-03-14 15:36:00 +08:00
|
|
|
|
|
|
|
func TestValue(t *testing.T) {
|
2021-05-01 01:15:30 +08:00
|
|
|
logger := DefaultLogger
|
2021-05-17 16:34:28 +08:00
|
|
|
logger = With(logger, "ts", DefaultTimestamp, "caller", DefaultCaller)
|
2021-08-31 10:14:57 +08:00
|
|
|
_ = logger.Log(LevelInfo, "msg", "helloworld")
|
2021-10-21 17:39:33 +08:00
|
|
|
|
|
|
|
logger = DefaultLogger
|
|
|
|
logger = With(logger)
|
|
|
|
_ = logger.Log(LevelDebug, "msg", "helloworld")
|
|
|
|
|
|
|
|
var v1 interface{}
|
|
|
|
got := Value(context.Background(), v1)
|
|
|
|
if got != v1 {
|
|
|
|
t.Errorf("Value() = %v, want %v", got, v1)
|
|
|
|
}
|
|
|
|
var v2 Valuer = func(ctx context.Context) interface{} {
|
|
|
|
return 3
|
|
|
|
}
|
|
|
|
got = Value(context.Background(), v2)
|
|
|
|
res := got.(int)
|
|
|
|
if res != 3 {
|
|
|
|
t.Errorf("Value() = %v, want %v", res, 3)
|
|
|
|
}
|
2021-03-14 15:36:00 +08:00
|
|
|
}
|