DHT-kademlia-P2Psec/cmd/main_test.go

38 lines
794 B
Go
Raw Permalink Normal View History

2024-09-13 07:04:40 +02:00
package main
import (
"testing"
)
func TestParseIP(t *testing.T) {
cases := []struct {
input string
host string
port uint64
}{
{"localhost:8080", "localhost", 8080},
{"127.0.0.1:8080", "127.0.0.1", 8080},
{"131.159.15.61:6001", "131.159.15.61", 6001},
{"[::1]:8080", "::1", 8080},
{"[2001:4ca0:2001:11:226:b9ff:fe7d:84ed]:6001", "2001:4ca0:2001:11:226:b9ff:fe7d:84ed", 6001},
}
for _, c := range cases {
var host string
var port uint64
host, port, _ = parseIP(c.input)
if host != c.host || port != c.port {
t.Errorf("parseIP(%s): Expected %s, %d; got %s, %d", c.input, c.host, c.port, host, port)
}
}
}
func TestParseConfig(t *testing.T) {
config := ParseConfig("testdata/test.ini")
if config.PrefixLength != 5 {
t.Fatal("Read wrong value!")
}
}