mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
27 lines
527 B
Go
27 lines
527 B
Go
package log
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestGetLoggerFromContext(t *testing.T) {
|
|
logger := InitLoggerForServer()
|
|
ctx := WithLogger(context.Background(), logger)
|
|
cancel, cancelFunc := context.WithCancel(ctx)
|
|
defer cancelFunc()
|
|
timeout, c := context.WithTimeout(cancel, time.Second*10)
|
|
defer c()
|
|
l := GetLogger(timeout)
|
|
if logger != l {
|
|
panic("not same")
|
|
}
|
|
cancel = WithoutLogger(cancel)
|
|
defaultLogger := GetLogger(cancel)
|
|
if defaultLogger != L {
|
|
panic("not same")
|
|
}
|
|
logger.Debug("debug")
|
|
}
|