Xray-core/common/log/log_test.go

34 lines
566 B
Go
Raw Normal View History

2020-11-25 13:01:53 +02:00
package log_test
import (
"testing"
"github.com/google/go-cmp/cmp"
2020-12-04 03:36:16 +02:00
"github.com/xtls/xray-core/common/log"
"github.com/xtls/xray-core/common/net"
2020-11-25 13:01:53 +02:00
)
type testLogger struct {
value string
}
func (l *testLogger) Handle(msg log.Message) {
l.value = msg.String()
}
func TestLogRecord(t *testing.T) {
var logger testLogger
log.RegisterHandler(&logger)
ip := "8.8.8.8"
log.Record(&log.GeneralMessage{
Severity: log.Severity_Error,
Content: net.ParseAddress(ip),
})
if diff := cmp.Diff("[Error] "+ip, logger.value); diff != "" {
t.Error(diff)
}
}