github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/config/errors_test.go (about) 1 package p2pconfig 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 9 p2pmsg "github.com/onflow/flow-go/network/p2p/message" 10 ) 11 12 // TestErrInvalidLimitConfigRoundTrip ensures correct error formatting for ErrInvalidLimitConfig. 13 func TestErrInvalidLimitConfigRoundTrip(t *testing.T) { 14 controlMsg := p2pmsg.CtrlMsgGraft 15 limit := uint64(500) 16 17 e := fmt.Errorf("invalid rate limit value %d must be greater than 0", limit) 18 err := NewInvalidLimitConfigErr(controlMsg, e) 19 20 // tests the error message formatting. 21 expectedErrMsg := fmt.Errorf("invalid rpc control message %s validation limit configuration: %w", controlMsg, e).Error() 22 assert.Equal(t, expectedErrMsg, err.Error(), "the error message should be correctly formatted") 23 24 // tests the IsInvalidLimitConfigError function. 25 assert.True(t, IsInvalidLimitConfigError(err), "IsInvalidLimitConfigError should return true for ErrInvalidLimitConfig error") 26 27 // test IsInvalidLimitConfigError with a different error type. 28 dummyErr := fmt.Errorf("dummy error") 29 assert.False(t, IsInvalidLimitConfigError(dummyErr), "IsInvalidLimitConfigError should return false for non-ErrInvalidLimitConfig error") 30 }