forked from MetaCubeX/mihomo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters