(t *testing.T)
| 36 | } |
| 37 | |
| 38 | func TestExecuteExitsWithMappedCodes(t *testing.T) { |
| 39 | missingAuthFile := filepath.Join(t.TempDir(), "missing-auth.json") |
| 40 | |
| 41 | tests := []struct { |
| 42 | name string |
| 43 | args []string |
| 44 | env map[string]string |
| 45 | wantExitCode int |
| 46 | wantStdoutText string |
| 47 | wantStderrText string |
| 48 | }{ |
| 49 | { |
| 50 | name: "success", |
| 51 | args: []string{"--help"}, |
| 52 | wantExitCode: exitCodeSuccess, |
| 53 | wantStdoutText: "Usage:", |
| 54 | }, |
| 55 | { |
| 56 | name: "unknown command", |
| 57 | args: []string{"does-not-exist"}, |
| 58 | wantExitCode: exitCodeValidationError, |
| 59 | wantStderrText: `unknown command "does-not-exist"`, |
| 60 | }, |
| 61 | { |
| 62 | name: "json unknown command", |
| 63 | args: []string{"--output=json", "does-not-exist"}, |
| 64 | wantExitCode: exitCodeValidationError, |
| 65 | wantStdoutText: `"code":"unknown_command"`, |
| 66 | }, |
| 67 | { |
| 68 | name: "unsupported output format", |
| 69 | args: []string{"--output=yaml", "ls", "/"}, |
| 70 | wantExitCode: exitCodeValidationError, |
| 71 | wantStderrText: `unsupported output format "yaml"`, |
| 72 | }, |
| 73 | { |
| 74 | name: "unsupported output format with root help", |
| 75 | args: []string{"--help", "--output=yaml"}, |
| 76 | wantExitCode: exitCodeValidationError, |
| 77 | wantStderrText: `unsupported output format "yaml"`, |
| 78 | }, |
| 79 | { |
| 80 | name: "unsupported output format with command help", |
| 81 | args: []string{"put", "--help", "--output=yaml"}, |
| 82 | wantExitCode: exitCodeValidationError, |
| 83 | wantStderrText: `unsupported output format "yaml"`, |
| 84 | }, |
| 85 | { |
| 86 | name: "unsupported output format with help command", |
| 87 | args: []string{"help", "put", "--output=yaml"}, |
| 88 | wantExitCode: exitCodeValidationError, |
| 89 | wantStderrText: `unsupported output format "yaml"`, |
| 90 | }, |
| 91 | { |
| 92 | name: "unsupported output format before help command", |
| 93 | args: []string{"--output=yaml", "help", "put"}, |
| 94 | wantExitCode: exitCodeValidationError, |
| 95 | wantStderrText: `unsupported output format "yaml"`, |
nothing calls this directly
no test coverage detected