修复缓存
Build docker and publish / build (20.15.1) (push) Successful in 7m26s

This commit is contained in:
2026-03-06 21:58:29 -08:00
parent 19932bb9f7
commit 4d913c1728
175 changed files with 437 additions and 12104 deletions
-1
View File
@@ -1 +0,0 @@
package migrate
-49
View File
@@ -1,49 +0,0 @@
package migrate
import (
"testing"
"github.com/perfect-panel/server/internal/model/node"
"github.com/perfect-panel/server/pkg/orm"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func getDSN() string {
cfg := orm.Config{
Addr: "127.0.0.1",
Username: "root",
Password: "mylove520",
Dbname: "vpnboard",
}
mc := orm.Mysql{
Config: cfg,
}
return mc.Dsn()
}
func TestMigrate(t *testing.T) {
t.Skipf("skip test")
m := Migrate(getDSN())
err := m.Migrate(2004)
if err != nil {
t.Errorf("failed to migrate: %v", err)
} else {
t.Log("migrate success")
}
}
func TestMysql(t *testing.T) {
db, err := gorm.Open(mysql.New(mysql.Config{
DSN: "root:mylove520@tcp(localhost:3306)/vpnboard",
}))
if err != nil {
t.Fatalf("Failed to connect to MySQL: %v", err)
}
err = db.Migrator().AutoMigrate(&node.Node{})
if err != nil {
t.Fatalf("Failed to auto migrate: %v", err)
return
}
t.Log("MySQL connection and migration successful")
}
-94
View File
@@ -1,94 +0,0 @@
package initialize
import (
"testing"
"github.com/perfect-panel/server/internal/config"
"github.com/perfect-panel/server/internal/model/system"
"github.com/perfect-panel/server/pkg/tool"
"github.com/stretchr/testify/assert"
)
func TestApplyVerifyCodeDefaults(t *testing.T) {
testCases := []struct {
name string
in config.VerifyCode
want config.VerifyCode
}{
{
name: "apply defaults when all zero",
in: config.VerifyCode{},
want: config.VerifyCode{
VerifyCodeExpireTime: 900,
VerifyCodeLimit: 15,
VerifyCodeInterval: 60,
},
},
{
name: "keep provided values",
in: config.VerifyCode{
VerifyCodeExpireTime: 901,
VerifyCodeLimit: 16,
VerifyCodeInterval: 61,
},
want: config.VerifyCode{
VerifyCodeExpireTime: 901,
VerifyCodeLimit: 16,
VerifyCodeInterval: 61,
},
},
{
name: "fix invalid non-positive values",
in: config.VerifyCode{
VerifyCodeExpireTime: -1,
VerifyCodeLimit: 0,
VerifyCodeInterval: -10,
},
want: config.VerifyCode{
VerifyCodeExpireTime: 900,
VerifyCodeLimit: 15,
VerifyCodeInterval: 60,
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
got := testCase.in
applyVerifyCodeDefaults(&got)
assert.Equal(t, testCase.want, got)
})
}
}
func TestVerifyCodeReflectUsesCanonicalKeys(t *testing.T) {
configs := []*system.System{
{Category: "verify_code", Key: "VerifyCodeExpireTime", Value: "901"},
{Category: "verify_code", Key: "VerifyCodeLimit", Value: "16"},
{Category: "verify_code", Key: "VerifyCodeInterval", Value: "61"},
}
var got config.VerifyCode
tool.SystemConfigSliceReflectToStruct(configs, &got)
applyVerifyCodeDefaults(&got)
assert.Equal(t, int64(901), got.VerifyCodeExpireTime)
assert.Equal(t, int64(16), got.VerifyCodeLimit)
assert.Equal(t, int64(61), got.VerifyCodeInterval)
}
func TestVerifyCodeReflectIgnoresLegacyKeys(t *testing.T) {
configs := []*system.System{
{Category: "verify_code", Key: "ExpireTime", Value: "901"},
{Category: "verify_code", Key: "Limit", Value: "16"},
{Category: "verify_code", Key: "Interval", Value: "61"},
}
var got config.VerifyCode
tool.SystemConfigSliceReflectToStruct(configs, &got)
applyVerifyCodeDefaults(&got)
assert.Equal(t, int64(900), got.VerifyCodeExpireTime)
assert.Equal(t, int64(15), got.VerifyCodeLimit)
assert.Equal(t, int64(60), got.VerifyCodeInterval)
}