MCPcopy
hub / github.com/ent/ent / TestUpdateNodes

Function TestUpdateNodes

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

Source from the content-addressed store, hash-verified

2101}
2102
2103func TestUpdateNodes(t *testing.T) {
2104 tests := []struct {
2105 name string
2106 spec *UpdateSpec
2107 prepare func(sqlmock.Sqlmock)
2108 wantErr bool
2109 wantAffected int
2110 }{
2111 {
2112 name: "without predicate",
2113 spec: &UpdateSpec{
2114 Node: &NodeSpec{
2115 Table: "users",
2116 ID: &FieldSpec{Column: "id", Type: field.TypeInt},
2117 },
2118 Fields: FieldMut{
2119 Set: []*FieldSpec{
2120 {Column: "age", Type: field.TypeInt, Value: 30},
2121 {Column: "name", Type: field.TypeString, Value: "Ariel"},
2122 },
2123 },
2124 },
2125 prepare: func(mock sqlmock.Sqlmock) {
2126 // Apply field changes.
2127 mock.ExpectExec(escape("UPDATE `users` SET `age` = ?, `name` = ?")).
2128 WithArgs(30, "Ariel").
2129 WillReturnResult(sqlmock.NewResult(0, 2))
2130 },
2131 wantAffected: 2,
2132 },
2133 {
2134 name: "with predicate",
2135 spec: &UpdateSpec{
2136 Node: &NodeSpec{
2137 Table: "users",
2138 ID: &FieldSpec{Column: "id", Type: field.TypeInt},
2139 },
2140 Fields: FieldMut{
2141 Clear: []*FieldSpec{
2142 {Column: "age", Type: field.TypeInt},
2143 {Column: "name", Type: field.TypeString},
2144 },
2145 },
2146 Predicate: func(s *sql.Selector) {
2147 s.Where(sql.EQ("name", "a8m"))
2148 },
2149 },
2150 prepare: func(mock sqlmock.Sqlmock) {
2151 // Clear fields.
2152 mock.ExpectExec(escape("UPDATE `users` SET `age` = NULL, `name` = NULL WHERE `name` = ?")).
2153 WithArgs("a8m").
2154 WillReturnResult(sqlmock.NewResult(0, 1))
2155 },
2156 wantAffected: 1,
2157 },
2158 {
2159 name: "with modifier",
2160 spec: &UpdateSpec{

Callers

nothing calls this directly

Calls 10

EQFunction · 0.92
ExprFunction · 0.92
OpenDBFunction · 0.92
UpdateNodesFunction · 0.85
RunMethod · 0.80
NewMethod · 0.80
escapeFunction · 0.70
WhereMethod · 0.65
OrderByMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…