github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/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  	"github.com/v2fly/v2ray-core/v5/common/log"
     9  	"github.com/v2fly/v2ray-core/v5/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  }