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.
13 var runErrorTest
= flag
.Bool("run_error_test", false, "let TestDialError check for dns errors")
15 type DialErrorTest
struct {
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",
53 "dial unix /etc/: ([pP]ermission denied|[sS]ocket operation on non-socket|[cC]onnection refused)",
57 func TestDialError(t
*testing
.T
) {
59 t
.Logf("test disabled; use --run_error_test to enable")
62 for i
, tt
:= range dialErrorTests
{
63 c
, e
:= Dial(tt
.Net
, tt
.Laddr
, tt
.Raddr
)
68 t
.Errorf("#%d: nil error, want match for %#q", i
, tt
.Pattern
)
72 match
, _
:= regexp
.MatchString(tt
.Pattern
, s
)
74 t
.Errorf("#%d: %q, want match for %#q", i
, s
, tt
.Pattern
)