compareJSON compares two JSON objects and returns a human-readable diff
(expected, actual map[string]interface{})
| 448 | |
| 449 | // compareJSON compares two JSON objects and returns a human-readable diff |
| 450 | func compareJSON(expected, actual map[string]interface{}) string { |
| 451 | var diffs []string |
| 452 | for key, expectedVal := range expected { |
| 453 | actualVal, exists := actual[key] |
| 454 | if !exists { |
| 455 | diffs = append(diffs, fmt.Sprintf(" Missing field: %q", key)) |
| 456 | continue |
| 457 | } |
| 458 | if fmt.Sprintf("%v", expectedVal) != fmt.Sprintf("%v", actualVal) { |
| 459 | diffs = append(diffs, fmt.Sprintf(" Field %q: expected %v, got %v", key, expectedVal, actualVal)) |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | if len(diffs) > 0 { |
| 464 | expectedJSON, _ := json.MarshalIndent(expected, " ", " ") |
| 465 | actualJSON, _ := json.MarshalIndent(actual, " ", " ") |
| 466 | return fmt.Sprintf("Expected:\n %s\n\n Actual:\n %s\n\n Differences:\n%s", |
| 467 | expectedJSON, actualJSON, strings.Join(diffs, "\n")) |
| 468 | } |
| 469 | |
| 470 | return "" |
| 471 | } |
| 472 | |
| 473 | func TestWebhookUpdate(t *testing.T) { |
| 474 | s := makeTestServer(t) |
no outgoing calls
no test coverage detected