ce7cb702218693d08ea6d83464d2457c9250027c

This commit is contained in:
ms2k 2026-11-12 20:46:28 +09:00
commit 34c5f8963c

View file

@ -0,0 +1,36 @@
package main
import (
"math"
"reflect"
"testing"
)
func TestParse(t *testing.T) {
for _, test := range []struct {
name string
args []string
want config
}{
{"defaults", nil, config{4143, 4140, 2102, []uint16{4190, 4191}}},
{"custom", []string{"--inbound=10123", "--outbound=10456", "--proxy-uid=9876", "--ignore-inbound=80,443"}, config{10123, 10456, 9876, []uint16{80, 443}}},
{"bounds", []string{"--inbound=65535", "--outbound=1", "--proxy-uid=4294967295", "--ignore-inbound="}, config{math.MaxUint16, 1, math.MaxUint32, nil}},
} {
t.Run(test.name, func(t *testing.T) {
got, err := parse(test.args)
if err != nil || !reflect.DeepEqual(got, test.want) {
t.Fatalf("parse = %+v, %v; want %+v", got, err, test.want)
}
})
}
for _, args := range [][]string{
{"--inbound=0"}, {"--outbound=0"}, {"--inbound=65536"}, {"--outbound=-1"},
{"--proxy-uid=4294967296"}, {"--proxy-uid=-1"},
{"--ignore-inbound=0"}, {"--ignore-inbound=80,"}, {"--ignore-inbound=65536"},
{"--ignore-inbound=garbage"}, {"--unknown"}, {"extra"},
} {
if _, err := parse(args); err == nil {
t.Errorf("accepted %v", args)
}
}
}