(t *testing.T, file string, label string)
| 501 | } |
| 502 | |
| 503 | func loadJSONContractFile(t *testing.T, file string, label string) jsonGoldenContract { |
| 504 | t.Helper() |
| 505 | |
| 506 | data, err := os.ReadFile(file) |
| 507 | if err != nil { |
| 508 | t.Fatalf("read %s %s: %v", label, file, err) |
| 509 | } |
| 510 | |
| 511 | var raw struct { |
| 512 | Definitions map[string]json.RawMessage `json:"definitions"` |
| 513 | Commands map[string]map[string]json.RawMessage `json:"commands"` |
| 514 | } |
| 515 | if err := json.Unmarshal(data, &raw); err != nil { |
| 516 | t.Fatalf("decode raw %s %s: %v", label, file, err) |
| 517 | } |
| 518 | if len(raw.Definitions) == 0 { |
| 519 | t.Fatalf("%s %s has no definitions", label, file) |
| 520 | } |
| 521 | if len(raw.Commands) == 0 { |
| 522 | t.Fatalf("%s %s has no commands", label, file) |
| 523 | } |
| 524 | |
| 525 | requiredCommandFields := []string{ |
| 526 | "top_level", |
| 527 | "result_wrapper", |
| 528 | "input", |
| 529 | "result_input", |
| 530 | "result", |
| 531 | "statuses", |
| 532 | "kinds", |
| 533 | "warnings", |
| 534 | } |
| 535 | for command, fields := range raw.Commands { |
| 536 | for _, field := range requiredCommandFields { |
| 537 | if _, ok := fields[field]; !ok { |
| 538 | t.Errorf("%s for %q missing %q", label, command, field) |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | var contract jsonGoldenContract |
| 544 | if err := json.Unmarshal(data, &contract); err != nil { |
| 545 | t.Fatalf("decode %s %s: %v", label, file, err) |
| 546 | } |
| 547 | return normalizeGoldenContract(contract) |
| 548 | } |
| 549 | |
| 550 | func loadJSONGoldenSuccessOutputs(t *testing.T) map[string]json.RawMessage { |
| 551 | t.Helper() |
no test coverage detected