(t *testing.T)
| 277 | } |
| 278 | |
| 279 | func TestRenderCommandErrorWritesJSONErrorToStdout(t *testing.T) { |
| 280 | var stdout bytes.Buffer |
| 281 | var stderr bytes.Buffer |
| 282 | cmd := &cobra.Command{Use: "rm"} |
| 283 | cmd.SetOut(&stdout) |
| 284 | cmd.SetErr(&stderr) |
| 285 | cmd.Flags().String(outputFlag, "json", "") |
| 286 | |
| 287 | renderCommandError(cmd, errors.New("failed")) |
| 288 | |
| 289 | if got := stderr.String(); got != "" { |
| 290 | t.Fatalf("stderr = %q, want empty", got) |
| 291 | } |
| 292 | rendered := stdout.String() |
| 293 | got := decodeJSONErrorResponse(t, rendered) |
| 294 | if got.OK { |
| 295 | t.Fatalf("ok = true, want false") |
| 296 | } |
| 297 | if got.SchemaVersion != jsonSchemaVersion { |
| 298 | t.Fatalf("schema_version = %q, want %q", got.SchemaVersion, jsonSchemaVersion) |
| 299 | } |
| 300 | if got.Command != "rm" { |
| 301 | t.Fatalf("command = %q, want rm", got.Command) |
| 302 | } |
| 303 | if got.Error.Message != "failed" { |
| 304 | t.Fatalf("message = %q, want failed", got.Error.Message) |
| 305 | } |
| 306 | if got.Error.Code != "command_failed" { |
| 307 | t.Fatalf("code = %q, want command_failed", got.Error.Code) |
| 308 | } |
| 309 | if got.Error.Details != nil { |
| 310 | t.Fatalf("details = %+v, want nil", got.Error.Details) |
| 311 | } |
| 312 | if len(got.Warnings) != 0 { |
| 313 | t.Fatalf("warnings = %+v, want empty", got.Warnings) |
| 314 | } |
| 315 | if !strings.Contains(rendered, `"warnings":[]`) { |
| 316 | t.Fatalf("output = %q, want warnings array", rendered) |
| 317 | } |
| 318 | if strings.Contains(rendered, `"details"`) { |
| 319 | t.Fatalf("output = %q, want details omitted for generic error", rendered) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | func TestRenderCommandErrorIncludesDeprecatedCommandWarning(t *testing.T) { |
| 324 | var stdout bytes.Buffer |
nothing calls this directly
no test coverage detected