mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
52
app/log/log_test.go
Normal file
52
app/log/log_test.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package log_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/xtls/xray-core/v1/app/log"
|
||||
"github.com/xtls/xray-core/v1/common"
|
||||
clog "github.com/xtls/xray-core/v1/common/log"
|
||||
"github.com/xtls/xray-core/v1/testing/mocks"
|
||||
)
|
||||
|
||||
func TestCustomLogHandler(t *testing.T) {
|
||||
mockCtl := gomock.NewController(t)
|
||||
defer mockCtl.Finish()
|
||||
|
||||
var loggedValue []string
|
||||
|
||||
mockHandler := mocks.NewLogHandler(mockCtl)
|
||||
mockHandler.EXPECT().Handle(gomock.Any()).AnyTimes().DoAndReturn(func(msg clog.Message) {
|
||||
loggedValue = append(loggedValue, msg.String())
|
||||
})
|
||||
|
||||
log.RegisterHandlerCreator(log.LogType_Console, func(lt log.LogType, options log.HandlerCreatorOptions) (clog.Handler, error) {
|
||||
return mockHandler, nil
|
||||
})
|
||||
|
||||
logger, err := log.New(context.Background(), &log.Config{
|
||||
ErrorLogLevel: clog.Severity_Debug,
|
||||
ErrorLogType: log.LogType_Console,
|
||||
AccessLogType: log.LogType_None,
|
||||
})
|
||||
common.Must(err)
|
||||
|
||||
common.Must(logger.Start())
|
||||
|
||||
clog.Record(&clog.GeneralMessage{
|
||||
Severity: clog.Severity_Debug,
|
||||
Content: "test",
|
||||
})
|
||||
|
||||
if len(loggedValue) < 2 {
|
||||
t.Fatal("expected 2 log messages, but actually ", loggedValue)
|
||||
}
|
||||
|
||||
if loggedValue[1] != "[Debug] test" {
|
||||
t.Fatal("expected '[Debug] test', but actually ", loggedValue[1])
|
||||
}
|
||||
|
||||
common.Must(logger.Close())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue