()
| 810 | d.bodyExp, d.bodyAct, d.bodyNoise = exp, act, noise |
| 811 | } |
| 812 | func (d *DiffsPrinter) Render() error { |
| 813 | diffs := []string{} |
| 814 | |
| 815 | // Status (only when actually different) |
| 816 | if d.statusExp != d.statusAct { |
| 817 | s := sprintDiff(d.statusExp, d.statusAct, "status") |
| 818 | if s != "" { |
| 819 | diffs = append(diffs, s) |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | // Headers (skip when empty/identical) |
| 824 | s := sprintDiffHeader(d.headerExp, d.headerAct) |
| 825 | if s != "" { |
| 826 | diffs = append(diffs, s) |
| 827 | } |
| 828 | |
| 829 | // Body (skip when empty/identical) |
| 830 | if len(d.bodyExp) != 0 || len(d.bodyAct) != 0 { |
| 831 | bE, bA := []byte(d.bodyExp), []byte(d.bodyAct) |
| 832 | if json.Valid(bE) && json.Valid(bA) { |
| 833 | difference, err := sprintJSONDiff(bE, bA, "body", d.bodyNoise) |
| 834 | if err != nil { |
| 835 | difference = sprintDiff(d.bodyExp, d.bodyAct, "body") |
| 836 | } |
| 837 | if difference != "" { |
| 838 | diffs = append(diffs, difference) |
| 839 | } |
| 840 | } else { |
| 841 | // Non-JSON; only show when something exists to show |
| 842 | if !isBlankPair(d.bodyExp, d.bodyAct) { |
| 843 | difference := expectActualTableWithColors(d.bodyExp, d.bodyAct, "body", false) |
| 844 | diffs = append(diffs, difference) |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | // If nothing to show and no array-index warning, render nothing. |
| 850 | if len(diffs) == 0 && !d.hasarrayIndexMismatch { |
| 851 | return nil |
| 852 | } |
| 853 | |
| 854 | var opts []tablewriter.Option |
| 855 | opts = append(opts, tablewriter.WithHeaderAutoWrap(tw.WrapNone)) |
| 856 | opts = append(opts, tablewriter.WithRowAutoWrap(tw.WrapNone)) |
| 857 | opts = append(opts, tablewriter.WithTrimSpace(tw.Off)) |
| 858 | if !models.IsAnsiDisabled { |
| 859 | opts = append(opts, tablewriter.WithRenderer(newDiffTableRenderer())) |
| 860 | } |
| 861 | opts = append(opts, tablewriter.WithRowAlignment(tw.AlignCenter)) |
| 862 | table := tablewriter.NewTable(d.out, opts...) |
| 863 | table.Header([]string{d.testCase}) |
| 864 | |
| 865 | for _, e := range diffs { |
| 866 | if strings.TrimSpace(e) != "" { |
| 867 | table.Append([]string{e}) |
| 868 | } |
| 869 | } |
no test coverage detected