MCPcopy
hub / github.com/go-gorm/gorm / TestUpdateWithMissWhere

Function TestUpdateWithMissWhere

tests/upsert_test.go:360–375  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

358}
359
360func TestUpdateWithMissWhere(t *testing.T) {
361 type User struct {
362 ID uint `gorm:"column:id;<-:create"`
363 Name string `gorm:"column:name"`
364 }
365 user := User{ID: 1, Name: "king"}
366 tx := DB.Session(&gorm.Session{DryRun: true}).Save(&user)
367
368 if err := tx.Error; err != nil {
369 t.Fatalf("failed to update user,missing where condition,err=%+v", err)
370 }
371
372 if !regexp.MustCompile("WHERE .id. = [^ ]+$").MatchString(tx.Statement.SQL.String()) {
373 t.Fatalf("invalid updating SQL, got %v", tx.Statement.SQL.String())
374 }
375}

Callers

nothing calls this directly

Calls 3

SaveMethod · 0.80
SessionMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected