优化结构

This commit is contained in:
Yvan
2026-08-27 16:20:37 +08:00
parent 001e39da50
commit 653414a1da
54 changed files with 1257 additions and 3450 deletions
+15 -17
View File
@@ -64,21 +64,21 @@ func TestStorageIntegrationConfigRoundTrip(t *testing.T) {
},
Minio: &config.ObjectStore{Endpoint: "127.0.0.1:9000", Bucket: "local", ForcePathStyle: true},
}
if err := saveStorageIntegrationConfig(db, storage); err != nil {
if err := dataintegration.SaveStorageConfig(db, storage); err != nil {
t.Fatal(err)
}
email := &config.Email{
To: "ops@example.com", From: "mailer@example.com", Host: "smtp.example.com",
Secret: "smtp-secret", Nickname: "Kra", Port: 465, IsSSL: true,
}
if err := saveEmailIntegrationConfig(db, email); err != nil {
if err := dataintegration.SaveEmailConfig(db, email); err != nil {
t.Fatal(err)
}
if err := db.Create(&dataintegration.ConfigPO{Kind: integrationbiz.IntegrationKindPayment, Provider: "wechat-pay", Config: `{"merchant_id":"123"}`}).Error; err != nil {
t.Fatal(err)
}
loaded, found, err := loadStorageIntegrationConfig(db)
loaded, found, err := dataintegration.LoadStorageConfig(db)
if err != nil {
t.Fatal(err)
}
@@ -95,7 +95,7 @@ func TestStorageIntegrationConfigRoundTrip(t *testing.T) {
t.Fatalf("qiniu configuration = %#v", loaded.Qiniu)
}
loadedEmail, found, err := loadEmailIntegrationConfig(db)
loadedEmail, found, err := dataintegration.LoadEmailConfig(db)
if err != nil || !found {
t.Fatalf("email configuration found=%v, err=%v", found, err)
}
@@ -104,17 +104,17 @@ func TestStorageIntegrationConfigRoundTrip(t *testing.T) {
}
var storageCount, emailCount, paymentCount int64
if err = db.Model(&dataintegration.ConfigPO{}).Where("kind = ?", integrationKindStorage).Count(&storageCount).Error; err != nil {
if err = db.Model(&dataintegration.ConfigPO{}).Where("kind = ?", "storage").Count(&storageCount).Error; err != nil {
t.Fatal(err)
}
if err = db.Model(&dataintegration.ConfigPO{}).Where("kind = ?", integrationbiz.IntegrationKindPayment).Count(&paymentCount).Error; err != nil {
t.Fatal(err)
}
if err = db.Model(&dataintegration.ConfigPO{}).Where("kind = ?", integrationKindEmail).Count(&emailCount).Error; err != nil {
if err = db.Model(&dataintegration.ConfigPO{}).Where("kind = ?", "email").Count(&emailCount).Error; err != nil {
t.Fatal(err)
}
if storageCount != int64(len(storageProviderNames)) {
t.Fatalf("storage row count = %d, want %d", storageCount, len(storageProviderNames))
if storageCount != 8 {
t.Fatalf("storage row count = %d, want 8", storageCount)
}
if paymentCount != 1 {
t.Fatalf("payment row count = %d, want 1", paymentCount)
@@ -130,7 +130,7 @@ func TestResolveStorageIntegrationConfigMigratesLegacyOnlyOnce(t *testing.T) {
Type: "qiniu",
Qiniu: &config.Qiniu{Bucket: "legacy", SecretKey: "legacy-secret"},
}
loaded, err := resolveStorageIntegrationConfig(db, legacy)
loaded, err := dataintegration.ResolveStorageConfig(db, legacy)
if err != nil {
t.Fatal(err)
}
@@ -142,7 +142,7 @@ func TestResolveStorageIntegrationConfigMigratesLegacyOnlyOnce(t *testing.T) {
Type: "minio",
Minio: &config.ObjectStore{Bucket: "must-not-replace-database"},
}
loaded, err = resolveStorageIntegrationConfig(db, other)
loaded, err = dataintegration.ResolveStorageConfig(db, other)
if err != nil {
t.Fatal(err)
}
@@ -169,14 +169,14 @@ func TestMaskStorageSecretsLeavesUnconfiguredProvidersEmpty(t *testing.T) {
func TestResolveEmailIntegrationConfigMigratesLegacyOnlyOnce(t *testing.T) {
db := openIntegrationConfigTestDB(t)
legacy := &config.Email{To: "ops@example.com", From: "old@example.com", Host: "smtp.old.example.com", Secret: "old-secret", Port: 465, IsSSL: true}
loaded, err := resolveEmailIntegrationConfig(db, legacy)
loaded, err := dataintegration.ResolveEmailConfig(db, legacy)
if err != nil {
t.Fatal(err)
}
if loaded.Host != legacy.Host || loaded.Secret != legacy.Secret {
t.Fatalf("migrated email = %#v", loaded)
}
loaded, err = resolveEmailIntegrationConfig(db, &config.Email{Host: "must-not-replace.example.com"})
loaded, err = dataintegration.ResolveEmailConfig(db, &config.Email{Host: "must-not-replace.example.com"})
if err != nil {
t.Fatal(err)
}
@@ -245,11 +245,9 @@ func TestPersistRuntimeConfigReplacesActiveStorage(t *testing.T) {
if err != nil {
t.Fatal(err)
}
reloadableDB := &reloadableDB{}
reloadableDB.current.Store(db)
d := &Data{
runtime: config.NewStore(&config.Config{Data: &config.Data{}, Admin: currentAdmin}),
gormDB: reloadableDB,
gormDB: newReloadableDB(db, nil),
storage: currentStorage,
}
d.databaseReady.Store(true)
@@ -274,11 +272,11 @@ func TestPersistRuntimeConfigReplacesActiveStorage(t *testing.T) {
if _, err = os.Stat(filepath.Join(newRoot, "active.txt")); err != nil {
t.Fatalf("active storage did not write to the new root: %v", err)
}
loaded, found, err := loadStorageIntegrationConfig(db)
loaded, found, err := dataintegration.LoadStorageConfig(db)
if err != nil || !found || loaded.Type != "local" {
t.Fatalf("database storage config = %#v, found=%v, err=%v", loaded, found, err)
}
loadedEmail, found, err := loadEmailIntegrationConfig(db)
loadedEmail, found, err := dataintegration.LoadEmailConfig(db)
if err != nil || !found || loadedEmail.Secret != "runtime-secret" {
t.Fatalf("database email config = %#v, found=%v, err=%v", loadedEmail, found, err)
}