MCPcopy Create free account
hub / github.com/QuantumNous/new-api / TestLockForUpdateEmitsRowLock

Function TestLockForUpdateEmitsRowLock

model/locking_test.go:18–38  ·  view source on GitHub ↗

lockForUpdate must emit FOR UPDATE on databases that support it and skip it on SQLite, where the syntax does not exist. The dummy dialector is used because SQLite drivers strip locking clauses from the generated SQL, which would mask what the helper itself does.

(t *testing.T)

Source from the content-addressed store, hash-verified

16// The dummy dialector is used because SQLite drivers strip locking clauses
17// from the generated SQL, which would mask what the helper itself does.
18func TestLockForUpdateEmitsRowLock(t *testing.T) {
19 dummyDB, err := gorm.Open(tests.DummyDialector{}, &gorm.Config{DryRun: true})
20 require.NoError(t, err)
21 buildSQL := func() string {
22 var rows []Redemption
23 return lockForUpdate(dummyDB).Where("id = ?", 1).Find(&rows).Statement.SQL.String()
24 }
25
26 t.Cleanup(func() {
27 common.SetDatabaseTypes(common.DatabaseTypeSQLite, common.DatabaseTypeSQLite)
28 })
29
30 common.SetDatabaseTypes(common.DatabaseTypeMySQL, common.DatabaseTypeSQLite)
31 assert.Contains(t, buildSQL(), "FOR UPDATE")
32
33 common.SetDatabaseTypes(common.DatabaseTypePostgreSQL, common.DatabaseTypeSQLite)
34 assert.Contains(t, buildSQL(), "FOR UPDATE")
35
36 common.SetDatabaseTypes(common.DatabaseTypeSQLite, common.DatabaseTypeSQLite)
37 assert.NotContains(t, buildSQL(), "FOR UPDATE")
38}

Callers

nothing calls this directly

Calls 5

SetDatabaseTypesFunction · 0.92
lockForUpdateFunction · 0.85
OpenMethod · 0.80
ContainsMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected