MCPcopy
hub / github.com/ent/ent / TestIsConstraintError

Function TestIsConstraintError

dialect/sql/sqlgraph/graph_test.go:2601–2719  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2599}
2600
2601func TestIsConstraintError(t *testing.T) {
2602 tests := []struct {
2603 name string
2604 errMessage string
2605 expectedConstraint bool
2606 expectedFK bool
2607 expectedUnique bool
2608 expectedCheck bool
2609 }{
2610 {
2611 name: "MySQL FK",
2612 errMessage: `insert node to table "pets": Error 1452: Cannot add or update a child row: a foreign key` +
2613 " constraint fails (`test`.`pets`, CONSTRAINT `pets_users_pets` FOREIGN KEY (`user_pets`) REFERENCES " +
2614 "`users` (`id`) ON DELETE SET NULL)",
2615 expectedConstraint: true,
2616 expectedFK: true,
2617 expectedUnique: false,
2618 expectedCheck: false,
2619 },
2620 {
2621 name: "SQLite FK",
2622 errMessage: `insert node to table "pets": FOREIGN KEY constraint failed`,
2623 expectedConstraint: true,
2624 expectedFK: true,
2625 expectedUnique: false,
2626 expectedCheck: false,
2627 },
2628 {
2629 name: "Postgres FK",
2630 errMessage: `insert node to table "pets": pq: insert or update on table "pets" violates foreign key constraint "pets_users_pets"`,
2631 expectedConstraint: true,
2632 expectedFK: true,
2633 expectedUnique: false,
2634 expectedCheck: false,
2635 },
2636 {
2637 name: "MySQL FK",
2638 errMessage: "Error 1451: Cannot delete or update a parent row: a foreign key constraint " +
2639 "fails (`test`.`groups`, CONSTRAINT `groups_group_infos_info` FOREIGN KEY (`group_info`) REFERENCES `group_infos` (`id`))",
2640 expectedConstraint: true,
2641 expectedFK: true,
2642 expectedUnique: false,
2643 expectedCheck: false,
2644 },
2645 {
2646 name: "SQLite FK",
2647 errMessage: `FOREIGN KEY constraint failed`,
2648 expectedConstraint: true,
2649 expectedFK: true,
2650 expectedUnique: false,
2651 expectedCheck: false,
2652 },
2653 {
2654 name: "Postgres FK",
2655 errMessage: `pq: update or delete on table "group_infos" violates foreign key constraint "groups_group_infos_info" on table "groups"`,
2656 expectedConstraint: true,
2657 expectedFK: true,
2658 expectedUnique: false,

Callers

nothing calls this directly

Calls 6

IsUniqueConstraintErrorFunction · 0.85
IsCheckConstraintErrorFunction · 0.85
RunMethod · 0.80
NewMethod · 0.80
IsConstraintErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…