mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
Every import of the module changes, not only the seven packages that
moved out of sdk/pkg: Go requires the major version in the path from v2
on. Both happen in one pass —
go run github.com/go-admin-team/go-admin-core/tools/coreupgrade@v2.0.0 -w -v2 .
go mod tidy
— which is the command the release notes give, run here as a consumer
would run it. 210 imports across 95 files.
The compatibility shims this used are gone in v2, so the paths that
moved had to move: sdk/pkg/captcha, sdk/pkg/jwtauth and its user
package, sdk/pkg/response and sdk/pkg/casbin.
The count of unformatted files is unchanged at 34, none of them touched
by this: the tool reformats a file only if it was already gofmt clean,
so a migration cannot disappear into whitespace.
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package tools
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/go-admin-team/go-admin-core/v2/sdk/config"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// The generator reads MySQL's information_schema and nothing else. Every entry
|
|
// point says so, but the guard used to be written pkg.Assert(true, ...), which
|
|
// never fires: pkg.Assert panics when its condition is false. A non-mysql
|
|
// deployment therefore fell through to a query built on a zero-value *gorm.DB.
|
|
//
|
|
// tx is nil on purpose - the assertion has to come before anything touches it.
|
|
func TestCodegenModelsRefuseNonMySQLDrivers(t *testing.T) {
|
|
previous := config.DatabaseConfig.Driver
|
|
config.DatabaseConfig.Driver = "postgres"
|
|
t.Cleanup(func() { config.DatabaseConfig.Driver = previous })
|
|
|
|
cases := map[string]func(*gorm.DB){
|
|
"DBTables.GetPage": func(tx *gorm.DB) {
|
|
_, _, _ = new(DBTables).GetPage(tx, 10, 1)
|
|
},
|
|
"DBTables.Get": func(tx *gorm.DB) {
|
|
_, _ = (&DBTables{TableName: "sys_user"}).Get(tx)
|
|
},
|
|
"DBColumns.GetPage": func(tx *gorm.DB) {
|
|
_, _, _ = (&DBColumns{TableName: "sys_user"}).GetPage(tx, 10, 1)
|
|
},
|
|
"DBColumns.GetList": func(tx *gorm.DB) {
|
|
_, _ = (&DBColumns{TableName: "sys_user"}).GetList(tx)
|
|
},
|
|
}
|
|
|
|
for name, call := range cases {
|
|
t.Run(name, func(t *testing.T) {
|
|
defer func() {
|
|
raised := recover()
|
|
if raised == nil {
|
|
t.Fatal("driver is not mysql and the call went through anyway")
|
|
}
|
|
msg, ok := raised.(string)
|
|
if !ok || !strings.Contains(msg, "目前只支持mysql数据库") {
|
|
t.Fatalf("want the mysql-only assertion, got %v", raised)
|
|
}
|
|
}()
|
|
call(nil)
|
|
})
|
|
}
|
|
}
|