Merge from mainline (167278:168000).
[official-gcc/graphite-test-results.git] / libgo / go / net / net_test.go
blobfebfc0a5f42a61d05a614c6a2712bd19e7a4f260
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package net
7 import (
8 "flag"
9 "regexp"
10 "testing"
13 var runErrorTest = flag.Bool("run_error_test", false, "let TestDialError check for dns errors")
15 type DialErrorTest struct {
16 Net string
17 Laddr string
18 Raddr string
19 Pattern string
22 var dialErrorTests = []DialErrorTest{
24 "datakit", "", "mh/astro/r70",
25 "dial datakit mh/astro/r70: unknown network datakit",
28 "tcp", "", "127.0.0.1:☺",
29 "dial tcp 127.0.0.1:☺: unknown port tcp/☺",
32 "tcp", "", "no-such-name.google.com.:80",
33 "dial tcp no-such-name.google.com.:80: lookup no-such-name.google.com.( on .*)?: no (.*)",
36 "tcp", "", "no-such-name.no-such-top-level-domain.:80",
37 "dial tcp no-such-name.no-such-top-level-domain.:80: lookup no-such-name.no-such-top-level-domain.( on .*)?: no (.*)",
40 "tcp", "", "no-such-name:80",
41 `dial tcp no-such-name:80: lookup no-such-name\.(.*\.)?( on .*)?: no (.*)`,
44 "tcp", "", "mh/astro/r70:http",
45 "dial tcp mh/astro/r70:http: lookup mh/astro/r70: invalid domain name",
48 "unix", "", "/etc/file-not-found",
49 "dial unix /etc/file-not-found: [nN]o such file or directory",
52 "unix", "", "/etc/",
53 "dial unix /etc/: ([pP]ermission denied|[sS]ocket operation on non-socket|[cC]onnection refused)",
57 func TestDialError(t *testing.T) {
58 if !*runErrorTest {
59 t.Logf("test disabled; use --run_error_test to enable")
60 return
62 for i, tt := range dialErrorTests {
63 c, e := Dial(tt.Net, tt.Laddr, tt.Raddr)
64 if c != nil {
65 c.Close()
67 if e == nil {
68 t.Errorf("#%d: nil error, want match for %#q", i, tt.Pattern)
69 continue
71 s := e.String()
72 match, _ := regexp.MatchString(tt.Pattern, s)
73 if !match {
74 t.Errorf("#%d: %q, want match for %#q", i, s, tt.Pattern)