| 35 | } |
| 36 | |
| 37 | func TestFailedExecExitCode(t *testing.T) { |
| 38 | testCases := []struct { |
| 39 | doc string |
| 40 | command []string |
| 41 | expectedExitCode int |
| 42 | }{ |
| 43 | { |
| 44 | doc: "executable not found", |
| 45 | command: []string{"nonexistent"}, |
| 46 | expectedExitCode: 127, |
| 47 | }, |
| 48 | { |
| 49 | doc: "executable cannot be invoked", |
| 50 | command: []string{"/etc"}, |
| 51 | expectedExitCode: 126, |
| 52 | }, |
| 53 | } |
| 54 | |
| 55 | for _, tc := range testCases { |
| 56 | t.Run(tc.doc, func(t *testing.T) { |
| 57 | ctx := setupTest(t) |
| 58 | apiClient := testEnv.APIClient() |
| 59 | |
| 60 | cID := container.Run(ctx, t, apiClient) |
| 61 | |
| 62 | result, err := container.Exec(ctx, apiClient, cID, tc.command) |
| 63 | assert.NilError(t, err) |
| 64 | |
| 65 | assert.Equal(t, result.ExitCode, tc.expectedExitCode) |
| 66 | }) |
| 67 | } |
| 68 | } |