mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 14:17:56 +01:00
wtwire: use require package for fuzz tests
Simplify code by using the require package instead of t.Fatal().
This commit is contained in:
@@ -3,8 +3,9 @@ package wtwire
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// prefixWithMsgType takes []byte and adds a wire protocol prefix
|
// prefixWithMsgType takes []byte and adds a wire protocol prefix
|
||||||
@@ -43,26 +44,15 @@ func harness(t *testing.T, data []byte, emptyMsg Message) {
|
|||||||
|
|
||||||
// We will serialize the message into a new bytes buffer.
|
// We will serialize the message into a new bytes buffer.
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
if _, err := WriteMessage(&b, msg, 0); err != nil {
|
_, err = WriteMessage(&b, msg, 0)
|
||||||
// Could not serialize message into bytes buffer, panic.
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deserialize the message from the serialized bytes buffer, and then
|
// Deserialize the message from the serialized bytes buffer, and then
|
||||||
// assert that the original message is equal to the newly deserialized
|
// assert that the original message is equal to the newly deserialized
|
||||||
// message.
|
// message.
|
||||||
newMsg, err := ReadMessage(&b, 0)
|
newMsg, err := ReadMessage(&b, 0)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
// Could not deserialize message from bytes buffer, panic.
|
require.Equal(t, msg, newMsg)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(msg, newMsg) {
|
|
||||||
// Deserialized message and original message are not
|
|
||||||
// deeply equal.
|
|
||||||
t.Fatal("deserialized message and original message " +
|
|
||||||
"are not deeply equal.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzCreateSessionReply(f *testing.F) {
|
func FuzzCreateSessionReply(f *testing.F) {
|
||||||
|
|||||||
Reference in New Issue
Block a user