(t *testing.T)
| 115 | } |
| 116 | |
| 117 | func TestExecStartConsoleSize(t *testing.T) { |
| 118 | tests := []struct { |
| 119 | doc string |
| 120 | options ExecStartOptions |
| 121 | expErr string |
| 122 | expReq container.ExecStartRequest |
| 123 | }{ |
| 124 | { |
| 125 | doc: "without TTY", |
| 126 | options: ExecStartOptions{ |
| 127 | Detach: true, |
| 128 | TTY: false, |
| 129 | ConsoleSize: ConsoleSize{Height: 100, Width: 200}, |
| 130 | }, |
| 131 | expErr: "console size is only supported when TTY is enabled", |
| 132 | }, |
| 133 | { |
| 134 | doc: "with TTY", |
| 135 | options: ExecStartOptions{ |
| 136 | Detach: true, |
| 137 | TTY: true, |
| 138 | ConsoleSize: ConsoleSize{Height: 100, Width: 200}, |
| 139 | }, |
| 140 | expReq: container.ExecStartRequest{ |
| 141 | Detach: true, |
| 142 | Tty: true, |
| 143 | ConsoleSize: &[2]uint{100, 200}, |
| 144 | }, |
| 145 | }, |
| 146 | } |
| 147 | for _, tc := range tests { |
| 148 | t.Run(tc.doc, func(t *testing.T) { |
| 149 | var actualReq container.ExecStartRequest |
| 150 | client, err := New( |
| 151 | WithMockClient(func(req *http.Request) (*http.Response, error) { |
| 152 | if tc.expErr != "" { |
| 153 | return nil, errors.New("should not have made API request") |
| 154 | } |
| 155 | if err := json.NewDecoder(req.Body).Decode(&actualReq); err != nil { |
| 156 | return nil, err |
| 157 | } |
| 158 | |
| 159 | return mockJSONResponse(http.StatusOK, nil, ExecStartResult{})(req) |
| 160 | }), |
| 161 | ) |
| 162 | assert.NilError(t, err) |
| 163 | |
| 164 | _, err = client.ExecStart(t.Context(), "exec_id", tc.options) |
| 165 | if tc.expErr != "" { |
| 166 | assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument)) |
| 167 | assert.Check(t, is.ErrorContains(err, tc.expErr)) |
| 168 | assert.Check(t, is.DeepEqual(actualReq, tc.expReq)) |
| 169 | } else { |
| 170 | assert.NilError(t, err) |
| 171 | assert.Check(t, is.DeepEqual(actualReq, tc.expReq)) |
| 172 | } |
| 173 | }) |
| 174 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…