diff options
| author | Mikio Hara <mikioh.mikioh@gmail.com> | 2015-04-17 14:55:07 +0900 |
|---|---|---|
| committer | Mikio Hara <mikioh.mikioh@gmail.com> | 2015-04-18 01:43:35 +0000 |
| commit | d0f3100b477fb42d37cdb948ebbf80b3951141d2 (patch) | |
| tree | f764f56feadcd8c7b2bbc5d7976e9c575921cece /src/net/error_test.go | |
| parent | 93402383eac407108b045bdd70e67aaaaeb0a96c (diff) | |
| download | go-d0f3100b477fb42d37cdb948ebbf80b3951141d2.tar.xz | |
net: break up TestErrorNil into Test{Dial,Listen,ListenPacket}Error
Change-Id: I7c6c91a0551aacb49e1beb4a39215b93c8c7fcfa
Reviewed-on: https://go-review.googlesource.com/8997
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/error_test.go')
| -rw-r--r-- | src/net/error_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/net/error_test.go b/src/net/error_test.go index 8448eb1c39..d7f502ef19 100644 --- a/src/net/error_test.go +++ b/src/net/error_test.go @@ -150,6 +150,9 @@ func TestDialError(t *testing.T) { c.Close() continue } + if c != nil { + t.Errorf("Dial returned non-nil interface %T(%v) with err != nil", c, c) + } if err = parseDialError(err); err != nil { t.Errorf("#%d: %v", i, err) continue @@ -166,6 +169,11 @@ var listenErrorTests = []struct { {"tcp", "127.0.0.1:☺"}, {"tcp", "no-such-name:80"}, {"tcp", "mh/astro/r70:http"}, + + {"tcp", "127.0.0.1:0"}, + + {"unix", "/path/to/somewhere"}, + {"unixpacket", "/path/to/somewhere"}, } func TestListenError(t *testing.T) { @@ -191,6 +199,49 @@ func TestListenError(t *testing.T) { ln.Close() continue } + if ln != nil { + t.Errorf("Listen returned non-nil interface %T(%v) with err != nil", ln, ln) + } + if err = parseDialError(err); err != nil { + t.Errorf("#%d: %v", i, err) + continue + } + } +} + +var listenPacketErrorTests = []struct { + network, address string +}{ + {"foo", ""}, + {"bar", "baz"}, + {"datakit", "mh/astro/r70"}, + {"udp", "127.0.0.1:☺"}, + {"udp", "no-such-name:80"}, + {"udp", "mh/astro/r70:http"}, +} + +func TestListenPacketError(t *testing.T) { + switch runtime.GOOS { + case "plan9": + t.Skipf("%s does not have full support of socktest", runtime.GOOS) + } + + origTestHookLookupIP := testHookLookupIP + defer func() { testHookLookupIP = origTestHookLookupIP }() + testHookLookupIP = func(fn func(string) ([]IPAddr, error), host string) ([]IPAddr, error) { + return nil, &DNSError{Err: "listen error test", Name: "name", Server: "server", IsTimeout: true} + } + + for i, tt := range listenPacketErrorTests { + c, err := ListenPacket(tt.network, tt.address) + if err == nil { + t.Errorf("#%d: should fail; %s:%s->", i, tt.network, c.LocalAddr()) + c.Close() + continue + } + if c != nil { + t.Errorf("ListenPacket returned non-nil interface %T(%v) with err != nil", c, c) + } if err = parseDialError(err); err != nil { t.Errorf("#%d: %v", i, err) continue |
