Based on QuantumNous/new-api v1.0.0-rc.36 (shallow history squashed). - CNY quota display mode: RMB-denominated top-up and crediting across Epay/Waffo channels - New CheckinButton in both authenticated and public headers (Turnstile supported) - New /subscribe page with public plan snapshot, Alipay/balance payment, auto group upgrade/reset - New /docs 12-section beginner guide with anchor navigation - New home PromoBanner linking to /docs; i18n synced (en/zh/zh-TW/fr/ja/ru/vi) - README: document custom features, live demo https://ai.88531.cn
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/utils/tests"
|
|
)
|
|
|
|
// 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.
|
|
func TestLockForUpdateEmitsRowLock(t *testing.T) {
|
|
dummyDB, err := gorm.Open(tests.DummyDialector{}, &gorm.Config{DryRun: true})
|
|
require.NoError(t, err)
|
|
buildSQL := func() string {
|
|
var rows []Redemption
|
|
return lockForUpdate(dummyDB).Where("id = ?", 1).Find(&rows).Statement.SQL.String()
|
|
}
|
|
|
|
t.Cleanup(func() {
|
|
common.SetDatabaseTypes(common.DatabaseTypeSQLite, common.DatabaseTypeSQLite)
|
|
})
|
|
|
|
common.SetDatabaseTypes(common.DatabaseTypeMySQL, common.DatabaseTypeSQLite)
|
|
assert.Contains(t, buildSQL(), "FOR UPDATE")
|
|
|
|
common.SetDatabaseTypes(common.DatabaseTypePostgreSQL, common.DatabaseTypeSQLite)
|
|
assert.Contains(t, buildSQL(), "FOR UPDATE")
|
|
|
|
common.SetDatabaseTypes(common.DatabaseTypeSQLite, common.DatabaseTypeSQLite)
|
|
assert.NotContains(t, buildSQL(), "FOR UPDATE")
|
|
}
|