proxy-pool/examples/config/examples_test.go
youfak 4de3ffb85f
Some checks are pending
ci / test (ubuntu-latest) (push) Waiting to run
ci / test (windows-latest) (push) Waiting to run
ci / race (push) Waiting to run
feat: add ephemeral proxy activity pool
2026-07-29 12:51:18 +08:00

65 lines
1.5 KiB
Go

package configexamples
import (
"os"
"path/filepath"
"strings"
"testing"
projectconfig "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)
}
}
}