[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [goptlib/master] Add tests for resolveAddr.



commit 0f8fbff83c68e6b7c7db96a39b994ae288309bae
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Sat Nov 9 18:33:42 2013 -0800

    Add tests for resolveAddr.
---
 pt_test.go |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/pt_test.go b/pt_test.go
index 793635b..01dd0ad 100644
--- a/pt_test.go
+++ b/pt_test.go
@@ -2,6 +2,7 @@ package pt
 
 import (
 	"bytes"
+	"net"
 	"os"
 	"sort"
 	"testing"
@@ -170,6 +171,48 @@ func TestGetClientTransports(t *testing.T) {
 	}
 }
 
+func TestResolveAddr(t *testing.T) {
+	badTests := [...]string{
+		"",
+		"1.2.3.4",
+		"1.2.3.4:",
+		"9999",
+		":9999",
+		"[1:2::3:4]",
+		"[1:2::3:4]:",
+		"[1::2::3:4]",
+		"1:2::3:4::9999",
+		"1:2:3:4::9999",
+		"localhost:9999",
+		"[localhost]:9999",
+	}
+	goodTests := [...]struct {
+		input    string
+		expected net.TCPAddr
+	}{
+		{"1.2.3.4:9999", net.TCPAddr{IP: net.ParseIP("1.2.3.4"), Port: 9999}},
+		{"[1:2::3:4]:9999", net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 9999}},
+		{"1:2::3:4:9999", net.TCPAddr{IP: net.ParseIP("1:2::3:4"), Port: 9999}},
+	}
+
+	for _, input := range badTests {
+		output, err := resolveAddr(input)
+		if err == nil {
+			t.Errorf("%q unexpectedly succeeded: %q", input, output)
+		}
+	}
+
+	for _, test := range goodTests {
+		output, err := resolveAddr(test.input)
+		if err != nil {
+			t.Errorf("%q unexpectedly returned an error: %s", test.input, err)
+		}
+		if !output.IP.Equal(test.expected.IP) || output.Port != test.expected.Port {
+			t.Errorf("%q â?? %q (expected %q)", test.input, output, test.expected)
+		}
+	}
+}
+
 func TestReadAuthCookie(t *testing.T) {
 	badTests := [...][]byte{
 		[]byte(""),



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits