github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/eth/mlog_test.go (about)

     1  package eth
     2  
     3  import (
     4  	"bytes"
     5  	"github.com/ethereumproject/go-ethereum/core/types"
     6  	"github.com/ethereumproject/go-ethereum/logger"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestMlogWireDelegateError(t *testing.T) {
    12  	logger.SetMlogEnabled(true)
    13  	logger.Reset()
    14  	// Set up a log sys with a local buffer instead of file
    15  	var b = new(bytes.Buffer)
    16  	sys := logger.NewMLogSystem(b, 0, logger.LogLevel(1), false)
    17  	logger.AddLogSystem(sys)
    18  
    19  	logger.MLogRegisterActive("wire")
    20  
    21  	// test with error
    22  	err := errResp(ErrMsgTooLarge, "%v > %v", 42, ProtocolMaxMsgSize)
    23  	mlogWireDelegate(nil, "receive", TxMsg, 42, "not castable to txs", err) // TODO: all msg codes
    24  
    25  	logger.Flush() // wait for messages to be delivered
    26  
    27  	if !strings.Contains(b.String(), errorToString[ErrMsgTooLarge]) {
    28  		t.Errorf("got: %v, want: %v", b.String(), errorToString[ErrMsgTooLarge])
    29  	}
    30  	b.Reset()
    31  
    32  	// test without error
    33  	err = nil
    34  	txs := []*types.Transaction{}                         // don't want to be nil
    35  	mlogWireDelegate(nil, "receive", TxMsg, 42, txs, err) // TODO: all msg codes
    36  
    37  	logger.Flush() // wait for messages to be delivered
    38  
    39  	if strings.Contains(b.String(), errorToString[ErrMsgTooLarge]) {
    40  		t.Errorf("got: %v, want: %v", errorToString[ErrMsgTooLarge], b.String())
    41  	}
    42  	b.Reset()
    43  }