ui优化
This commit is contained in:
1 parent
648b274c55
commit
18cb51670c
14 files changed
+420
-171
No files matched your search
@@ -38,6 +38,54 @@ func TestDefaultSettingsServiceAppliesProviderSettingsWithoutRestart(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuntimeSettingsGetenvProvidesDatabaseBackedStartupConfiguration(t *testing.T) {
|
||||
settingsPath := filepath.Join(t.TempDir(), ".env.local")
|
||||
fallbackValues := map[string]string{
|
||||
"ZHINIAN_SETTINGS_FILE": settingsPath,
|
||||
"ZHINIAN_AUTH_REQUIRED": "0",
|
||||
"ZHINIAN_AUTH_SESSION_SECRET": "environment-session-secret-that-is-long-enough",
|
||||
"ZHINIAN_BILLING_REQUIRED": "1",
|
||||
"ALI_OSS_ENDPOINT": "https://environment-oss.example.test",
|
||||
"ALI_OSS_BUCKET": "environment-bucket",
|
||||
"ALI_OSS_ACCESS_KEY_ID": "environment-access-key",
|
||||
"ALI_OSS_ACCESS_KEY_SECRET": "environment-access-secret",
|
||||
"ALI_OSS_PUBLIC_BASE_URL": "https://environment-cdn.example.test",
|
||||
"ZHINIAN_PROVIDER_TIMEOUT_MS": "1234",
|
||||
}
|
||||
fallback := func(name string) string { return fallbackValues[name] }
|
||||
repository := &applicationRuntimeSettingsRepository{values: map[string]string{
|
||||
"ZHINIAN_AUTH_REQUIRED": "1",
|
||||
"ZHINIAN_AUTH_SESSION_SECRET": "database-session-secret-that-is-long-enough",
|
||||
"ZHINIAN_BILLING_REQUIRED": "0",
|
||||
"ALI_OSS_ENDPOINT": "https://oss-cn-test.aliyuncs.com",
|
||||
"ALI_OSS_BUCKET": "database-bucket",
|
||||
"ALI_OSS_ACCESS_KEY_ID": "database-access-key",
|
||||
"ALI_OSS_ACCESS_KEY_SECRET": "database-access-secret",
|
||||
"ALI_OSS_PUBLIC_BASE_URL": "https://database-cdn.example.test",
|
||||
}}
|
||||
service := databaseSettingsService(fallback, repository)
|
||||
getenv, err := runtimeSettingsGetenv(context.Background(), fallback, service)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(repository.requestedKeys, settings.RuntimeSettingKeys()) {
|
||||
t.Fatalf("requested keys=%#v want %#v", repository.requestedKeys, settings.RuntimeSettingKeys())
|
||||
}
|
||||
auth, err := ParseAuthConfig(getenv)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !auth.Required || auth.SessionSecret != "database-session-secret-that-is-long-enough" {
|
||||
t.Fatalf("auth=%#v", auth)
|
||||
}
|
||||
if getenv("ZHINIAN_BILLING_REQUIRED") != "0" || getenv("ZHINIAN_PROVIDER_TIMEOUT_MS") != "1234" {
|
||||
t.Fatalf("billing=%q timeout=%q", getenv("ZHINIAN_BILLING_REQUIRED"), getenv("ZHINIAN_PROVIDER_TIMEOUT_MS"))
|
||||
}
|
||||
if _, configured, err := configuredOSSBlobStore(getenv); err != nil || !configured {
|
||||
t.Fatalf("configured OSS = %v err=%v", configured, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBillingAccountAndSettingsUseOneRuntimeSource(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), ".env.local")
|
||||
if err := os.WriteFile(path, []byte("ZHINIAN_BILLING_ACCOUNT_NAME=Original\nZHINIAN_BILLING_ACCOUNT_BANK=Old Bank\n"), 0o600); err != nil {
|
||||
@@ -276,9 +324,13 @@ func TestPrefixedBlobStoreKeepsApplicationStoragePathStable(t *testing.T) {
|
||||
|
||||
type recordingBlobStore struct{ putKey, readKey, deleteKey string }
|
||||
|
||||
type applicationRuntimeSettingsRepository struct{ values map[string]string }
|
||||
type applicationRuntimeSettingsRepository struct {
|
||||
values map[string]string
|
||||
requestedKeys []string
|
||||
}
|
||||
|
||||
func (repository *applicationRuntimeSettingsRepository) LoadRuntimeSettings(context.Context, []string) (map[string]string, error) {
|
||||
func (repository *applicationRuntimeSettingsRepository) LoadRuntimeSettings(_ context.Context, keys []string) (map[string]string, error) {
|
||||
repository.requestedKeys = append([]string(nil), keys...)
|
||||
values := map[string]string{}
|
||||
for key, value := range repository.values {
|
||||
values[key] = value
|
||||
|
||||
Reference in new issue
Block a user