(t *testing.T)
| 75 | } |
| 76 | |
| 77 | func TestProxyError(t *testing.T) { |
| 78 | testClient(t, func(e *cli.Engine, i *mocksdk.Interface) { |
| 79 | ctx, cancel := context.WithCancel(context.Background()) |
| 80 | defer cancel() |
| 81 | |
| 82 | i.On("WithContext", ctx).Return(i) |
| 83 | opts := structs.ProxyOptions{ |
| 84 | TLS: options.Bool(false), |
| 85 | } |
| 86 | i.On("Proxy", "test.example.org", 5000, mock.Anything, opts).Return(fmt.Errorf("err1")) |
| 87 | |
| 88 | port := rand.Intn(30000) + 10000 |
| 89 | |
| 90 | ch := make(chan *result) |
| 91 | |
| 92 | go func() { |
| 93 | res, err := testExecuteContext(ctx, e, fmt.Sprintf("proxy %d:test.example.org:5000", port), nil) |
| 94 | require.NoError(t, err) |
| 95 | ch <- res |
| 96 | }() |
| 97 | |
| 98 | time.Sleep(500 * time.Millisecond) |
| 99 | |
| 100 | cn, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", port)) |
| 101 | require.NoError(t, err) |
| 102 | |
| 103 | cn.Write([]byte("in")) |
| 104 | |
| 105 | data, _ := io.ReadAll(cn) |
| 106 | require.Len(t, data, 0) |
| 107 | |
| 108 | cancel() |
| 109 | // cli.ProxyCloser <- nil |
| 110 | |
| 111 | res := <-ch |
| 112 | |
| 113 | require.NotNil(t, res) |
| 114 | require.Equal(t, 0, res.Code) |
| 115 | res.RequireStderr(t, []string{"ERROR: err1"}) |
| 116 | res.RequireStdout(t, []string{ |
| 117 | fmt.Sprintf("proxying localhost:%d to test.example.org:5000", port), |
| 118 | fmt.Sprintf("connect: %d", port), |
| 119 | }) |
| 120 | }) |
| 121 | } |
nothing calls this directly
no test coverage detected