MCPcopy
hub / github.com/ent/ent / TestUpdateNode

Function TestUpdateNode

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

Source from the content-addressed store, hash-verified

1722}
1723
1724func TestUpdateNode(t *testing.T) {
1725 tests := []struct {
1726 name string
1727 spec *UpdateSpec
1728 prepare func(sqlmock.Sqlmock)
1729 wantErr bool
1730 wantUser *user
1731 }{
1732 {
1733 name: "fields/set",
1734 spec: &UpdateSpec{
1735 Node: &NodeSpec{
1736 Table: "users",
1737 Columns: []string{"id", "name", "age"},
1738 ID: &FieldSpec{Column: "id", Type: field.TypeInt, Value: 1},
1739 },
1740 Fields: FieldMut{
1741 Set: []*FieldSpec{
1742 {Column: "age", Type: field.TypeInt, Value: 30},
1743 {Column: "name", Type: field.TypeString, Value: "Ariel"},
1744 },
1745 },
1746 },
1747 prepare: func(mock sqlmock.Sqlmock) {
1748 mock.ExpectBegin()
1749 mock.ExpectExec(escape("UPDATE `users` SET `age` = ?, `name` = ? WHERE `id` = ?")).
1750 WithArgs(30, "Ariel", 1).
1751 WillReturnResult(sqlmock.NewResult(1, 1))
1752 mock.ExpectQuery(escape("SELECT `id`, `name`, `age` FROM `users` WHERE `id` = ?")).
1753 WithArgs(1).
1754 WillReturnRows(sqlmock.NewRows([]string{"id", "age", "name"}).
1755 AddRow(1, 30, "Ariel"))
1756 mock.ExpectCommit()
1757 },
1758 wantUser: &user{name: "Ariel", age: 30, id: 1},
1759 },
1760 {
1761 name: "fields/set_modifier",
1762 spec: &UpdateSpec{
1763 Node: &NodeSpec{
1764 Table: "users",
1765 Columns: []string{"id", "name", "age"},
1766 ID: &FieldSpec{Column: "id", Type: field.TypeInt, Value: 1},
1767 },
1768 Modifiers: []func(*sql.UpdateBuilder){
1769 func(u *sql.UpdateBuilder) {
1770 u.Set("name", sql.Expr(sql.Lower("name")))
1771 },
1772 },
1773 },
1774 prepare: func(mock sqlmock.Sqlmock) {
1775 mock.ExpectBegin()
1776 mock.ExpectExec(escape("UPDATE `users` SET `name` = LOWER(`name`) WHERE `id` = ?")).
1777 WithArgs(1).
1778 WillReturnResult(sqlmock.NewResult(1, 1))
1779 mock.ExpectQuery(escape("SELECT `id`, `name`, `age` FROM `users` WHERE `id` = ?")).
1780 WithArgs(1).
1781 WillReturnRows(sqlmock.NewRows([]string{"id", "age", "name"}).

Callers

nothing calls this directly

Calls 10

ExprFunction · 0.92
LowerFunction · 0.92
EQFunction · 0.92
OpenDBFunction · 0.92
UpdateNodeFunction · 0.85
RunMethod · 0.80
NewMethod · 0.80
escapeFunction · 0.70
WhereMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…