MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestExecuteJSONErrorOutputsValidateAgainstSchema

Function TestExecuteJSONErrorOutputsValidateAgainstSchema

cmd/root_test.go:134–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestExecuteJSONErrorOutputsValidateAgainstSchema(t *testing.T) {
135 missingAuthFile := filepath.Join(t.TempDir(), "missing-auth.json")
136
137 tests := []struct {
138 name string
139 args []string
140 env map[string]string
141 code string
142 }{
143 {
144 name: "unknown command",
145 args: []string{"--output=json", "does-not-exist"},
146 code: jsonErrorCodeUnknownCommand,
147 },
148 {
149 name: "auth required",
150 args: []string{"ls", "--output=json", "/"},
151 env: map[string]string{envAccessToken: "", envAuthFile: missingAuthFile},
152 code: jsonErrorCodeAuthRequired,
153 },
154 {
155 name: "structured output unsupported",
156 args: []string{"completion", "--output=json"},
157 code: jsonErrorCodeStructuredOutputUnsupported,
158 },
159 }
160
161 for _, tt := range tests {
162 t.Run(tt.name, func(t *testing.T) {
163 exitCode, stdout, stderr := executeExitTestSubprocess(t, tt.args, tt.env)
164 if exitCode == exitCodeSuccess {
165 t.Fatalf("exit code = 0, want non-zero\nstdout: %s\nstderr: %s", stdout, stderr)
166 }
167 if stderr != "" {
168 t.Fatalf("stderr = %q, want JSON error on stdout only", stderr)
169 }
170 got := decodeJSONErrorResponse(t, stdout)
171 if got.Error.Code != tt.code {
172 t.Fatalf("code = %q, want %q\nstdout: %s", got.Error.Code, tt.code, stdout)
173 }
174 })
175 }
176}
177
178func executeExitTestSubprocess(t *testing.T, args []string, env map[string]string) (int, string, string) {
179 t.Helper()

Callers

nothing calls this directly

Calls 2

decodeJSONErrorResponseFunction · 0.85

Tested by

no test coverage detected