github.com/xmplusdev/xray-core@v1.8.10/common/log/log_test.go (about) 1 package log_test 2 3 import ( 4 "testing" 5 6 "github.com/google/go-cmp/cmp" 7 "github.com/xmplusdev/xray-core/common/log" 8 "github.com/xmplusdev/xray-core/common/net" 9 ) 10 11 type testLogger struct { 12 value string 13 } 14 15 func (l *testLogger) Handle(msg log.Message) { 16 l.value = msg.String() 17 } 18 19 func TestLogRecord(t *testing.T) { 20 var logger testLogger 21 log.RegisterHandler(&logger) 22 23 ip := "8.8.8.8" 24 log.Record(&log.GeneralMessage{ 25 Severity: log.Severity_Error, 26 Content: net.ParseAddress(ip), 27 }) 28 29 if diff := cmp.Diff("[Error] "+ip, logger.value); diff != "" { 30 t.Error(diff) 31 } 32 }