Files
Zakk 868497a0e9 feat(service): a group may route through one selected member
An outbound group with several members is balanced by the observatory
(least ping). The group's setting now also names one member's share
link as Selected: the core template then keeps only that member, the
touch flags it on the connected entry, and PUT /outboundSelection sets
or clears it. A selection that matches no member is ignored, so a node
removed or renamed by a subscription update returns the group to
balancing instead of breaking it.
2026-09-19 23:17:05 +10:00

33 lines
830 B
Go

package v2ray
import "testing"
func TestApplySelection(t *testing.T) {
infos := []serverInfo{
socksInfo("proxy", "a"),
socksInfo("proxy", "b"),
socksInfo("other", "c"),
socksInfo("other", "d"),
}
selected := map[string]string{
"proxy": infos[1].Info.ExportToURL(),
"other": "socks5://gone:1080",
}
kept := applySelection(infos, func(outbound string) string { return selected[outbound] })
var names []string
for _, info := range kept {
names = append(names, info.Info.GetName())
}
// proxy keeps its selected member alone; other's selection matches no
// member, so the group stays balanced
want := []string{"b", "c", "d"}
if len(names) != len(want) {
t.Fatalf("kept %v, want %v", names, want)
}
for i := range want {
if names[i] != want[i] {
t.Fatalf("kept %v, want %v", names, want)
}
}
}