mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-12-02 20:01:51 +08:00
fix: clean up proxy settings and empty pool handling
This commit is contained in:
1 parent
05dd5b40e8
commit
4b037bf5b0
5 files changed
+502
-107
No files matched your search
@@ -41,6 +41,35 @@ func TestProxyPoolSnapshotMasksCredentialsAndDisabledHealth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyPoolEmptyResponseUsesArrays(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
pool *proxyPoolState
|
||||
}{
|
||||
{name: "uninitialized"},
|
||||
{name: "empty", pool: &proxyPoolState{}},
|
||||
{name: "member without switches", pool: &proxyPoolState{entries: []proxyPoolEntry{{ProxyPoolEntry: ProxyPoolEntry{ID: "a"}, RawURL: "http://a"}}}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s := &Server{m: &Manager{proxyPool: tc.pool}}
|
||||
w := httptest.NewRecorder()
|
||||
s.getProxyPool(w, httptest.NewRequest(http.MethodGet, "/api/settings/proxy-pool", nil))
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
var payload map[string]json.RawMessage
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, field := range []string{"entries", "switch_log"} {
|
||||
if raw := strings.TrimSpace(string(payload[field])); !strings.HasPrefix(raw, "[") {
|
||||
t.Errorf("%s must be a JSON array, got %s", field, raw)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyPoolSequentialSkipsUnhealthyAndDisabled(t *testing.T) {
|
||||
m := &Manager{proxyPool: &proxyPoolState{active: "a", entries: []proxyPoolEntry{
|
||||
{ProxyPoolEntry: ProxyPoolEntry{ID: "a", Enabled: true, Health: "healthy"}, RawURL: "http://a"},
|
||||
|
||||
Reference in new issue
Block a user