MCPcopy Index your code
hub / github.com/Masterminds/structable / TestUpdate

Function TestUpdate

structable_test.go:158–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestUpdate(t *testing.T) {
159 stool := newStool()
160 db := new(DBStub)
161
162 rec := New(db, "mysql").Bind("test_table", stool)
163
164 // with nil pointer field
165 if err := rec.Update(); err != nil {
166 t.Errorf("Update error: %s", err)
167 }
168
169 if !strings.Contains(db.LastExecSql, "number_of_legs = ") {
170 t.Error("Expected 'number_of_legs' in query")
171 }
172 if !strings.Contains(db.LastExecSql, "material = ") {
173 t.Error("Expected 'material' in query")
174 }
175
176 eargs := []interface{}{3, "Stainless Steel", 1, 2}
177 gotargs := db.LastExecArgs
178 for _, exp := range eargs {
179 found := false
180 for _, arg := range gotargs {
181 if arg == exp {
182 found = true
183 break
184 }
185 }
186 if !found {
187 t.Errorf("Could not find %v in %v", exp, gotargs)
188 }
189 }
190
191 // with allocated pointer
192 blue := "Blue"
193 stool.Color = &blue
194
195 if err := rec.Update(); err != nil {
196 t.Errorf("Update error: %s", err)
197 }
198
199 if !strings.Contains(db.LastExecSql, "number_of_legs = ") {
200 t.Error("Expected 'number_of_legs' in query")
201 }
202 if !strings.Contains(db.LastExecSql, "material = ") {
203 t.Error("Expected 'material' in query")
204 }
205 if !strings.Contains(db.LastExecSql, "color = ") {
206 t.Error("Expected 'color' in query")
207 }
208
209 eargs = []interface{}{3, "Stainless Steel", &blue, 1, 2}
210 gotargs = db.LastExecArgs
211 for _, exp := range eargs {
212 found := false
213 for _, arg := range gotargs {
214 if arg == exp {
215 found = true

Callers

nothing calls this directly

Calls 4

newStoolFunction · 0.85
NewFunction · 0.85
BindMethod · 0.65
UpdateMethod · 0.65

Tested by

no test coverage detected