MCPcopy Index your code
hub / github.com/coder/coder / TestIsConnectionErr

Function TestIsConnectionErr

codersdk/client_internal_test.go:35–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33const jsonCT = "application/json"
34
35func TestIsConnectionErr(t *testing.T) {
36 t.Parallel()
37
38 type tc = struct {
39 name string
40 err error
41 expectedResult bool
42 }
43
44 cases := []tc{
45 {
46 // E.g. "no such host"
47 name: "DNSError",
48 err: &net.DNSError{
49 Err: "no such host",
50 Name: "foofoo",
51 Server: "1.1.1.1:53",
52 IsTimeout: false,
53 IsTemporary: false,
54 IsNotFound: true,
55 },
56 expectedResult: true,
57 },
58 {
59 // E.g. "connection refused"
60 name: "OpErr",
61 err: &net.OpError{
62 Op: "dial",
63 Net: "tcp",
64 Source: nil,
65 Addr: nil,
66 Err: &os.SyscallError{},
67 },
68 expectedResult: true,
69 },
70 {
71 name: "OpaqueError",
72 err: xerrors.Errorf("I'm opaque!"),
73 expectedResult: false,
74 },
75 }
76
77 for _, c := range cases {
78 t.Run(c.name, func(t *testing.T) {
79 t.Parallel()
80
81 require.Equal(t, c.expectedResult, IsConnectionError(c.err))
82 })
83 }
84}
85
86func Test_Client(t *testing.T) {
87 t.Parallel()

Callers

nothing calls this directly

Calls 4

IsConnectionErrorFunction · 0.85
RunMethod · 0.65
ErrorfMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected