channeldb/addr_test: inspect error string
Lets us match on more than static errors.
This commit is contained in:
parent
6ae55168b8
commit
6f605b2de2
@ -3,6 +3,7 @@ package channeldb
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/tor"
|
"github.com/lightningnetwork/lnd/tor"
|
||||||
@ -15,7 +16,7 @@ func (t unknownAddrType) String() string { return "unknown" }
|
|||||||
|
|
||||||
var addrTests = []struct {
|
var addrTests = []struct {
|
||||||
expAddr net.Addr
|
expAddr net.Addr
|
||||||
serErr error
|
serErr string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
expAddr: &net.TCPAddr{
|
expAddr: &net.TCPAddr{
|
||||||
@ -43,7 +44,7 @@ var addrTests = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
expAddr: unknownAddrType{},
|
expAddr: unknownAddrType{},
|
||||||
serErr: ErrUnknownAddressType,
|
serErr: ErrUnknownAddressType.Error(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,11 +56,21 @@ func TestAddrSerialization(t *testing.T) {
|
|||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
for _, test := range addrTests {
|
for _, test := range addrTests {
|
||||||
err := serializeAddr(&b, test.expAddr)
|
err := serializeAddr(&b, test.expAddr)
|
||||||
if err != test.serErr {
|
switch {
|
||||||
|
case err == nil && test.serErr != "":
|
||||||
|
t.Fatalf("expected serialization err for addr %v",
|
||||||
|
test.expAddr)
|
||||||
|
|
||||||
|
case err != nil && test.serErr == "":
|
||||||
|
t.Fatalf("unexpected serialization err for addr %v: %v",
|
||||||
|
test.expAddr, err)
|
||||||
|
|
||||||
|
case err != nil && !strings.Contains(err.Error(), test.serErr):
|
||||||
t.Fatalf("unexpected serialization err for addr %v, "+
|
t.Fatalf("unexpected serialization err for addr %v, "+
|
||||||
"want: %v, got %v",
|
"want: %v, got %v", test.expAddr, test.serErr,
|
||||||
test.expAddr, test.serErr, err)
|
err)
|
||||||
} else if test.serErr != nil {
|
|
||||||
|
case err != nil:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user