(t *testing.T)
| 22 | ) |
| 23 | |
| 24 | func TestBadDials(t *testing.T) { |
| 25 | t.Parallel() |
| 26 | |
| 27 | t.Run("badReq", func(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | |
| 30 | testCases := []struct { |
| 31 | name string |
| 32 | url string |
| 33 | opts *websocket.DialOptions |
| 34 | rand util.ReaderFunc |
| 35 | nilCtx bool |
| 36 | }{ |
| 37 | { |
| 38 | name: "badURL", |
| 39 | url: "://noscheme", |
| 40 | }, |
| 41 | { |
| 42 | name: "badURLScheme", |
| 43 | url: "ftp://nhooyr.io", |
| 44 | }, |
| 45 | { |
| 46 | name: "badTLS", |
| 47 | url: "wss://totallyfake.nhooyr.io", |
| 48 | }, |
| 49 | { |
| 50 | name: "badReader", |
| 51 | rand: func(p []byte) (int, error) { |
| 52 | return 0, io.EOF |
| 53 | }, |
| 54 | }, |
| 55 | { |
| 56 | name: "nilContext", |
| 57 | url: "http://localhost", |
| 58 | nilCtx: true, |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | for _, tc := range testCases { |
| 63 | tc := tc |
| 64 | t.Run(tc.name, func(t *testing.T) { |
| 65 | t.Parallel() |
| 66 | |
| 67 | var ctx context.Context |
| 68 | var cancel func() |
| 69 | if !tc.nilCtx { |
| 70 | ctx, cancel = context.WithTimeout(context.Background(), time.Second*5) |
| 71 | defer cancel() |
| 72 | } |
| 73 | |
| 74 | if tc.rand == nil { |
| 75 | tc.rand = rand.Reader.Read |
| 76 | } |
| 77 | |
| 78 | _, _, err := websocket.ExportedDial(ctx, tc.url, tc.opts, tc.rand) |
| 79 | assert.Error(t, err) |
| 80 | }) |
| 81 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…