github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/common/log/log_test.go (about)

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