MCPcopy
hub / github.com/keploy/keploy / RenderAppender

Method RenderAppender

pkg/matcher/utils.go:943–984  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

941}
942
943func (d *DiffsPrinter) RenderAppender() error {
944 //Only show difference for the response body
945 diffs := []string{}
946 pass := true
947
948 if d.typeExp != d.typeAct {
949 diffs = append(diffs, sprintDiff(d.typeExp, d.typeAct, "request body type"))
950 pass = false
951 }
952 if !pass {
953 err := d.TableWriter(diffs)
954 if err != nil {
955 return err
956 }
957 return nil
958 }
959
960 if len(d.bodyExp) != 0 || len(d.bodyAct) != 0 {
961 pass = false
962 bE, bA := []byte(d.bodyExp), []byte(d.bodyAct)
963 if json.Valid(bE) && json.Valid(bA) {
964 difference, err := sprintJSONDiff(bE, bA, "response", d.bodyNoise)
965 if err != nil {
966 difference = sprintDiff(d.bodyExp, d.bodyAct, "response")
967 }
968 diffs = append(diffs, difference)
969 } else {
970 // If either body is not valid JSON, show expected as red and actual as green
971 difference := expectActualTableWithColors(d.bodyExp, d.bodyAct, "response", false)
972 diffs = append(diffs, difference)
973 }
974 }
975 if !pass {
976 err := d.TableWriter(diffs)
977 if err != nil {
978 return err
979 }
980
981 }
982
983 return nil
984}
985
986// SchemaError represents a single schema mismatch
987type SchemaError struct {

Callers 1

printAndRenderLogsFunction · 0.80

Calls 5

TableWriterMethod · 0.95
sprintDiffFunction · 0.85
sprintJSONDiffFunction · 0.85
ValidMethod · 0.80

Tested by

no test coverage detected