mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-20 00:18:55 +00:00
fix(setup): omit obsolete rate limit defaults
This commit is contained in:
@@ -495,10 +495,6 @@ func writeConfigFile(cfg *SetupConfig) error {
|
||||
APIKeyPrefix string `yaml:"api_key_prefix"`
|
||||
RateMultiplier float64 `yaml:"rate_multiplier"`
|
||||
} `yaml:"default"`
|
||||
RateLimit struct {
|
||||
RequestsPerMinute int `yaml:"requests_per_minute"`
|
||||
BurstSize int `yaml:"burst_size"`
|
||||
} `yaml:"rate_limit"`
|
||||
Timezone string `yaml:"timezone"`
|
||||
}{
|
||||
Server: cfg.Server,
|
||||
@@ -522,13 +518,6 @@ func writeConfigFile(cfg *SetupConfig) error {
|
||||
APIKeyPrefix: "sk-",
|
||||
RateMultiplier: 1.0,
|
||||
},
|
||||
RateLimit: struct {
|
||||
RequestsPerMinute int `yaml:"requests_per_minute"`
|
||||
BurstSize int `yaml:"burst_size"`
|
||||
}{
|
||||
RequestsPerMinute: 60,
|
||||
BurstSize: 10,
|
||||
},
|
||||
Timezone: tz,
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/lib/pq"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestDecideAdminBootstrap(t *testing.T) {
|
||||
@@ -231,6 +232,48 @@ func TestWriteConfigFileIncludesRedisUsername(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteConfigFileOmitsObsoleteRateLimit(t *testing.T) {
|
||||
t.Setenv("DATA_DIR", t.TempDir())
|
||||
|
||||
if err := writeConfigFile(&SetupConfig{
|
||||
Redis: RedisConfig{Host: "redis", Port: 6379, Username: "app-user"},
|
||||
Timezone: "UTC",
|
||||
}); err != nil {
|
||||
t.Fatalf("writeConfigFile() error = %v", err)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(GetConfigFilePath())
|
||||
if err != nil {
|
||||
t.Fatalf("ReadFile() error = %v", err)
|
||||
}
|
||||
var config map[string]any
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
t.Fatalf("generated config is invalid YAML: %v", err)
|
||||
}
|
||||
if rateLimit, exists := config["rate_limit"]; exists {
|
||||
fields, ok := rateLimit.(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("generated rate_limit must be a mapping: %#v", rateLimit)
|
||||
}
|
||||
for _, key := range []string{"requests_per_minute", "burst_size"} {
|
||||
if _, present := fields[key]; present {
|
||||
t.Fatalf("generated config contains obsolete rate_limit.%s: %s", key, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
redis, ok := config["redis"].(map[string]any)
|
||||
if !ok || redis["host"] != "redis" || redis["port"] != 6379 || redis["username"] != "app-user" {
|
||||
t.Fatalf("generated config lost Redis settings: %#v", config["redis"])
|
||||
}
|
||||
if config["timezone"] != "UTC" {
|
||||
t.Fatalf("generated config timezone = %#v, want UTC", config["timezone"])
|
||||
}
|
||||
defaults, ok := config["default"].(map[string]any)
|
||||
if !ok || defaults["user_concurrency"] != defaultUserConcurrency || defaults["api_key_prefix"] != "sk-" {
|
||||
t.Fatalf("generated config lost default settings: %#v", config["default"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDatabaseConnectionDSNsUseConfiguredTargetAndLegacyBootstrapDatabase(t *testing.T) {
|
||||
cfg := &DatabaseConfig{
|
||||
Host: "db",
|
||||
|
||||
Reference in New Issue
Block a user