lncfg: add tor addresses to test cases
This commit is contained in:
parent
197b920cac
commit
37f56ce976
@ -2,7 +2,10 @@
|
||||
|
||||
package lncfg
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// addressTest defines a test vector for an address that contains the non-
|
||||
// normalized input and the expected normalized output.
|
||||
@ -35,6 +38,34 @@ var (
|
||||
{"unix:///tmp/lnd.sock", "unix", "/tmp/lnd.sock", false, true},
|
||||
{"unix:/tmp/lnd.sock", "unix", "/tmp/lnd.sock", false, true},
|
||||
{"123", "tcp", "127.0.0.1:123", true, false},
|
||||
{
|
||||
"4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion",
|
||||
"tcp",
|
||||
"4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion:1234",
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion:9735",
|
||||
"tcp",
|
||||
"4acth47i6kxnvkewtm6q7ib2s3ufpo5sqbsnzjpbi7utijcltosqemad.onion:9735",
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"3g2upl4pq6kufc4m.onion",
|
||||
"tcp",
|
||||
"3g2upl4pq6kufc4m.onion:1234",
|
||||
false,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"3g2upl4pq6kufc4m.onion:9735",
|
||||
"tcp",
|
||||
"3g2upl4pq6kufc4m.onion:9735",
|
||||
false,
|
||||
false,
|
||||
},
|
||||
}
|
||||
invalidTestVectors = []string{
|
||||
"some string",
|
||||
@ -47,42 +78,41 @@ var (
|
||||
// normalized correctly.
|
||||
func TestAddresses(t *testing.T) {
|
||||
// First, test all correct addresses.
|
||||
for _, testVector := range addressTestVectors {
|
||||
for i, testVector := range addressTestVectors {
|
||||
addr := []string{testVector.address}
|
||||
normalized, err := NormalizeAddresses(addr, defaultTestPort)
|
||||
normalized, err := NormalizeAddresses(
|
||||
addr, defaultTestPort, net.ResolveTCPAddr,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to normalize address %s: %v",
|
||||
testVector.address, err)
|
||||
t.Fatalf("#%v: unable to normalize address %s: %v",
|
||||
i, testVector.address, err)
|
||||
}
|
||||
netAddr := normalized[0]
|
||||
if err != nil {
|
||||
t.Fatalf("unable to split normalized address: %v", err)
|
||||
t.Fatalf("#%v: unable to split normalized address: %v", i, err)
|
||||
}
|
||||
if netAddr.Network() != testVector.expectedNetwork ||
|
||||
netAddr.String() != testVector.expectedAddress {
|
||||
t.Fatalf(
|
||||
"mismatched address: expected %s://%s, got "+
|
||||
"%s://%s",
|
||||
testVector.expectedNetwork,
|
||||
t.Fatalf("#%v: mismatched address: expected %s://%s, "+
|
||||
"got %s://%s",
|
||||
i, testVector.expectedNetwork,
|
||||
testVector.expectedAddress,
|
||||
netAddr.Network(), netAddr.String(),
|
||||
)
|
||||
}
|
||||
isAddrLoopback := IsLoopback(normalized[0])
|
||||
if testVector.isLoopback != isAddrLoopback {
|
||||
t.Fatalf(
|
||||
"mismatched loopback detection: expected "+
|
||||
"%v, got %v for addr %s",
|
||||
testVector.isLoopback, isAddrLoopback,
|
||||
t.Fatalf("#%v: mismatched loopback detection: expected "+
|
||||
"%v, got %v for addr %s",
|
||||
i, testVector.isLoopback, isAddrLoopback,
|
||||
testVector.address,
|
||||
)
|
||||
}
|
||||
isAddrUnix := IsUnix(normalized[0])
|
||||
if testVector.isUnix != isAddrUnix {
|
||||
t.Fatalf(
|
||||
"mismatched unix detection: expected "+
|
||||
"%v, got %v for addr %s",
|
||||
testVector.isUnix, isAddrUnix,
|
||||
t.Fatalf("#%v: mismatched unix detection: expected "+
|
||||
"%v, got %v for addr %s",
|
||||
i, testVector.isUnix, isAddrUnix,
|
||||
testVector.address,
|
||||
)
|
||||
}
|
||||
@ -91,8 +121,11 @@ func TestAddresses(t *testing.T) {
|
||||
// Finally, test invalid inputs to see if they are handled correctly.
|
||||
for _, testVector := range invalidTestVectors {
|
||||
addr := []string{testVector}
|
||||
_, err := NormalizeAddresses(addr, defaultTestPort)
|
||||
_, err := NormalizeAddresses(
|
||||
addr, defaultTestPort, net.ResolveTCPAddr,
|
||||
)
|
||||
if err == nil {
|
||||
|
||||
t.Fatalf("expected error when parsing %v", testVector)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user