mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-01 08:36:38 +08:00
5bd21e2ac1
* feat: add comprehensive migration test for legacy columns - Add ExtraIPs, TCPListenAddr, UDPListenAddr to Node migration - Add ip_preference to Tunnel migration - Add test for very legacy database migration (1.x schema) - Include issue #211 tracking document Entire-Checkpoint: 0d086883c34a * fix: apply custom IP binding to forward and tunnel chain services Entire-Checkpoint: ceff329d4cf4
100 lines
3.4 KiB
Go
100 lines
3.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildForwardControlServiceNamesPauseResume(t *testing.T) {
|
|
base := "12_34_56"
|
|
want := []string{base + "_tcp", base + "_udp"}
|
|
|
|
for _, command := range []string{"PauseService", "ResumeService"} {
|
|
got := buildForwardControlServiceNames(base, command)
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("command %s expected %v, got %v", command, want, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildForwardControlServiceNamesDelete(t *testing.T) {
|
|
base := "12_34_56"
|
|
want := []string{base, base + "_tcp", base + "_udp"}
|
|
got := buildForwardControlServiceNames(base, " DeleteService ")
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("expected %v, got %v", want, got)
|
|
}
|
|
}
|
|
|
|
func TestBuildForwardServiceBaseCandidates(t *testing.T) {
|
|
got := buildForwardServiceBaseCandidates(12, 34, 56, []int64{56, 78, 90})
|
|
want := []string{"12_34_56", "12_34_78", "12_34_90", "12_34_0"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("expected %v, got %v", want, got)
|
|
}
|
|
}
|
|
|
|
func TestBuildForwardServiceBaseCandidatesWithZeroPreferred(t *testing.T) {
|
|
got := buildForwardServiceBaseCandidates(12, 34, 0, []int64{78, 0, 90})
|
|
want := []string{"12_34_0", "12_34_78", "12_34_90"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Fatalf("expected %v, got %v", want, got)
|
|
}
|
|
}
|
|
|
|
func TestShouldTryLegacySingleService(t *testing.T) {
|
|
if !shouldTryLegacySingleService("PauseService") {
|
|
t.Fatalf("PauseService should require legacy fallback")
|
|
}
|
|
if !shouldTryLegacySingleService("resumeService") {
|
|
t.Fatalf("ResumeService should require legacy fallback")
|
|
}
|
|
if shouldTryLegacySingleService("DeleteService") {
|
|
t.Fatalf("DeleteService should not require legacy fallback")
|
|
}
|
|
}
|
|
|
|
func TestIsAlreadyExistsMessage(t *testing.T) {
|
|
if !isAlreadyExistsMessage("service demo already exists") {
|
|
t.Fatalf("expected already exists message to be tolerated")
|
|
}
|
|
if !isAlreadyExistsMessage("服务已存在") {
|
|
t.Fatalf("expected Chinese already exists message to be tolerated")
|
|
}
|
|
if isAlreadyExistsMessage("listen tcp [::]:10001: bind: address already in use") {
|
|
t.Fatalf("address already in use must not be treated as already exists")
|
|
}
|
|
}
|
|
|
|
func TestBuildForwardServiceConfigs_UsesBindIPForListen(t *testing.T) {
|
|
forward := &forwardRecord{RemoteAddr: "1.2.3.4:80", Strategy: "fifo", TunnelID: 7}
|
|
node := &nodeRecord{TCPListenAddr: "[::]", UDPListenAddr: "[::]"}
|
|
services := buildForwardServiceConfigs("1_2_0", forward, nil, node, 22000, "10.9.8.7", nil, false)
|
|
if len(services) != 2 {
|
|
t.Fatalf("expected 2 services, got %d", len(services))
|
|
}
|
|
for _, svc := range services {
|
|
addr, _ := svc["addr"].(string)
|
|
if addr != "10.9.8.7:22000" {
|
|
t.Fatalf("expected bind IP address 10.9.8.7:22000, got %q", addr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBuildForwardServiceConfigs_DefaultListenAddrWhenBindIPEmpty(t *testing.T) {
|
|
forward := &forwardRecord{RemoteAddr: "1.2.3.4:80", Strategy: "fifo", TunnelID: 7}
|
|
node := &nodeRecord{TCPListenAddr: "0.0.0.0", UDPListenAddr: "[::]"}
|
|
services := buildForwardServiceConfigs("1_2_0", forward, nil, node, 22001, "", nil, false)
|
|
if len(services) != 2 {
|
|
t.Fatalf("expected 2 services, got %d", len(services))
|
|
}
|
|
tcpAddr, _ := services[0]["addr"].(string)
|
|
udpAddr, _ := services[1]["addr"].(string)
|
|
if tcpAddr != "0.0.0.0:22001" {
|
|
t.Fatalf("expected tcp addr 0.0.0.0:22001, got %q", tcpAddr)
|
|
}
|
|
if udpAddr != "[::]:22001" {
|
|
t.Fatalf("expected udp addr [::]:22001, got %q", udpAddr)
|
|
}
|
|
}
|