Commit ee9d148c authored by Mikio Hara's avatar Mikio Hara

net: add test for Dial and Listen arguments

R=dave, bradfitz
CC=golang-dev
https://golang.org/cl/7305081
parent d6331b44
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"reflect"
"regexp" "regexp"
"runtime" "runtime"
"testing" "testing"
...@@ -223,6 +224,31 @@ func TestDialError(t *testing.T) { ...@@ -223,6 +224,31 @@ func TestDialError(t *testing.T) {
} }
} }
var invalidDialAndListenArgTests = []struct {
net string
addr string
err error
}{
{"foo", "bar", &OpError{Op: "dial", Net: "foo", Addr: nil, Err: UnknownNetworkError("foo")}},
{"baz", "", &OpError{Op: "listen", Net: "baz", Addr: nil, Err: UnknownNetworkError("baz")}},
{"tcp", "", &OpError{Op: "dial", Net: "tcp", Addr: nil, Err: errMissingAddress}},
}
func TestInvalidDialAndListenArgs(t *testing.T) {
for _, tt := range invalidDialAndListenArgTests {
var err error
switch tt.err.(*OpError).Op {
case "dial":
_, err = Dial(tt.net, tt.addr)
case "listen":
_, err = Listen(tt.net, tt.addr)
}
if !reflect.DeepEqual(tt.err, err) {
t.Fatalf("got %#v; expected %#v", err, tt.err)
}
}
}
func TestDialTimeoutFDLeak(t *testing.T) { func TestDialTimeoutFDLeak(t *testing.T) {
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
// TODO(bradfitz): test on other platforms // TODO(bradfitz): test on other platforms
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment