mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-19 16:30:07 +08:00
Some checks are pending
Test / test (1.20, macos-13) (push) Waiting to run
Test / test (1.20, macos-latest) (push) Waiting to run
Test / test (1.20, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.20, ubuntu-latest) (push) Waiting to run
Test / test (1.20, windows-latest) (push) Waiting to run
Test / test (1.21, macos-13) (push) Waiting to run
Test / test (1.21, macos-latest) (push) Waiting to run
Test / test (1.21, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.21, ubuntu-latest) (push) Waiting to run
Test / test (1.21, windows-latest) (push) Waiting to run
Test / test (1.22, macos-13) (push) Waiting to run
Test / test (1.22, macos-latest) (push) Waiting to run
Test / test (1.22, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.22, ubuntu-latest) (push) Waiting to run
Test / test (1.22, windows-latest) (push) Waiting to run
Test / test (1.23, macos-13) (push) Waiting to run
Test / test (1.23, macos-latest) (push) Waiting to run
Test / test (1.23, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.23, ubuntu-latest) (push) Waiting to run
Test / test (1.23, windows-latest) (push) Waiting to run
Test / test (1.24, macos-13) (push) Waiting to run
Test / test (1.24, macos-latest) (push) Waiting to run
Test / test (1.24, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.24, ubuntu-latest) (push) Waiting to run
Test / test (1.24, windows-latest) (push) Waiting to run
Test / test (1.25, macos-13) (push) Waiting to run
Test / test (1.25, macos-latest) (push) Waiting to run
Test / test (1.25, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.25, ubuntu-latest) (push) Waiting to run
Test / test (1.25, windows-latest) (push) Waiting to run
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
The `port` field should not be allowed to be set to non-int values, as this would break some downstream assumptions that the option is an int.
This reverts commit 1b1f95aa9c.
93 lines
2.1 KiB
Go
93 lines
2.1 KiB
Go
package outbound
|
|
|
|
import "testing"
|
|
|
|
func TestNewMieru(t *testing.T) {
|
|
testCases := []struct {
|
|
option MieruOption
|
|
wantBaseAddr string
|
|
}{
|
|
{
|
|
option: MieruOption{
|
|
Name: "test",
|
|
Server: "1.2.3.4",
|
|
Port: 10000,
|
|
Transport: "TCP",
|
|
UserName: "test",
|
|
Password: "test",
|
|
},
|
|
wantBaseAddr: "1.2.3.4:10000",
|
|
},
|
|
{
|
|
option: MieruOption{
|
|
Name: "test",
|
|
Server: "2001:db8::1",
|
|
PortRange: "10001-10002",
|
|
Transport: "TCP",
|
|
UserName: "test",
|
|
Password: "test",
|
|
},
|
|
wantBaseAddr: "[2001:db8::1]:10001",
|
|
},
|
|
{
|
|
option: MieruOption{
|
|
Name: "test",
|
|
Server: "example.com",
|
|
Port: 10003,
|
|
Transport: "TCP",
|
|
UserName: "test",
|
|
Password: "test",
|
|
},
|
|
wantBaseAddr: "example.com:10003",
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
mieru, err := NewMieru(testCase.option)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if mieru.addr != testCase.wantBaseAddr {
|
|
t.Errorf("got addr %q, want %q", mieru.addr, testCase.wantBaseAddr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestBeginAndEndPortFromPortRange(t *testing.T) {
|
|
testCases := []struct {
|
|
input string
|
|
begin int
|
|
end int
|
|
hasErr bool
|
|
}{
|
|
{"1-10", 1, 10, false},
|
|
{"1000-2000", 1000, 2000, false},
|
|
{"65535-65535", 65535, 65535, false},
|
|
{"1", 0, 0, true},
|
|
{"1-", 0, 0, true},
|
|
{"-10", 0, 0, true},
|
|
{"a-b", 0, 0, true},
|
|
{"1-b", 0, 0, true},
|
|
{"a-10", 0, 0, true},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
begin, end, err := beginAndEndPortFromPortRange(testCase.input)
|
|
if testCase.hasErr {
|
|
if err == nil {
|
|
t.Errorf("beginAndEndPortFromPortRange(%s) should return an error", testCase.input)
|
|
}
|
|
} else {
|
|
if err != nil {
|
|
t.Errorf("beginAndEndPortFromPortRange(%s) should not return an error, but got %v", testCase.input, err)
|
|
}
|
|
if begin != testCase.begin {
|
|
t.Errorf("beginAndEndPortFromPortRange(%s) begin port mismatch, got %d, want %d", testCase.input, begin, testCase.begin)
|
|
}
|
|
if end != testCase.end {
|
|
t.Errorf("beginAndEndPortFromPortRange(%s) end port mismatch, got %d, want %d", testCase.input, end, testCase.end)
|
|
}
|
|
}
|
|
}
|
|
}
|