package configexamples import ( "os" "path/filepath" "strings" "testing" projectconfig "github.com/proxy-pool/proxy-pool/internal/config" ) func TestAllExamplesLoadStrictly(t *testing.T) { entries, err := filepath.Glob("*.yaml") if err != nil { t.Fatalf("glob examples: %v", err) } if len(entries) < 20 { t.Fatalf("configuration examples = %d, want at least 20", len(entries)) } for _, path := range entries { path := path t.Run(strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)), func(t *testing.T) { file, err := os.Open(path) if err != nil { t.Fatalf("open %s: %v", path, err) } defer file.Close() cfg, err := projectconfig.Load(file) if err != nil { t.Fatalf("load %s: %v", path, err) } assertExplicitProviderAuth(t, cfg) }) } } func TestMainConfigurationLoadsStrictly(t *testing.T) { path := filepath.Join("..", "..", "configs", "proxy-pool.yaml") file, err := os.Open(path) if err != nil { t.Fatalf("open %s: %v", path, err) } defer file.Close() cfg, err := projectconfig.Load(file) if err != nil { t.Fatalf("load %s: %v", path, err) } assertExplicitProviderAuth(t, cfg) } func assertExplicitProviderAuth(t *testing.T, cfg *projectconfig.Config) { t.Helper() for name, upstream := range cfg.Upstreams { if !upstream.Enabled { continue } if upstream.API.Auth.Type == "" { t.Errorf("upstream %s must explicitly set api.auth.type", name) } if upstream.ProxyAuth.Type == "" { t.Errorf("upstream %s must explicitly set proxyAuth.type", name) } } }