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