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

Function TestUnsupportedCommandsReturnJSONErrorEnvelope

cmd/json_contract_test.go:1331–1362  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1329}
1330
1331func TestUnsupportedCommandsReturnJSONErrorEnvelope(t *testing.T) {
1332 for _, name := range []string{"login", "completion"} {
1333 t.Run(name, func(t *testing.T) {
1334 var stdout, stderr bytes.Buffer
1335 cmd := &cobra.Command{Use: name}
1336 cmd.SetOut(&stdout)
1337 cmd.SetErr(&stderr)
1338 cmd.Flags().String(outputFlag, "json", "")
1339
1340 err := validateOutputFormat(cmd)
1341 if !errors.Is(err, output.ErrStructuredOutputUnsupported) {
1342 t.Fatalf("validateOutputFormat error = %v, want structured output unsupported", err)
1343 }
1344
1345 renderCommandError(cmd, err)
1346 if stderr.Len() != 0 {
1347 t.Fatalf("stderr = %q, want empty", stderr.String())
1348 }
1349
1350 got := decodeJSONErrorResponse(t, stdout.String())
1351 if got.OK {
1352 t.Fatalf("ok = true, want false")
1353 }
1354 if got.Error.Code != jsonErrorCodeStructuredOutputUnsupported {
1355 t.Fatalf("code = %q, want %q", got.Error.Code, jsonErrorCodeStructuredOutputUnsupported)
1356 }
1357 if got.Warnings == nil || len(got.Warnings) != 0 {
1358 t.Fatalf("warnings = %+v, want empty array", got.Warnings)
1359 }
1360 })
1361 }
1362}

Callers

nothing calls this directly

Calls 3

validateOutputFormatFunction · 0.85
renderCommandErrorFunction · 0.85
decodeJSONErrorResponseFunction · 0.85

Tested by

no test coverage detected