mirror of
https://github.com/apernet/hysteria.git
synced 2025-04-02 03:57:38 +03:00
test: add ut for PortUnion.Ports()
This commit is contained in:
parent
d65997c02b
commit
a9422e63be
1 changed files with 48 additions and 0 deletions
|
@ -2,6 +2,7 @@ package utils
|
|||
|
||||
import (
|
||||
"reflect"
|
||||
"slices"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -90,3 +91,50 @@ func TestParsePortUnion(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPortUnion_Ports(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
pu PortUnion
|
||||
want []uint16
|
||||
}{
|
||||
{
|
||||
name: "single port",
|
||||
pu: PortUnion{{1234, 1234}},
|
||||
want: []uint16{1234},
|
||||
},
|
||||
{
|
||||
name: "multiple ports",
|
||||
pu: PortUnion{{1234, 1236}},
|
||||
want: []uint16{1234, 1235, 1236},
|
||||
},
|
||||
{
|
||||
name: "multiple ports and ranges",
|
||||
pu: PortUnion{{1234, 1236}, {5678, 5680}, {9000, 9002}},
|
||||
want: []uint16{1234, 1235, 1236, 5678, 5679, 5680, 9000, 9001, 9002},
|
||||
},
|
||||
{
|
||||
name: "single port 65535",
|
||||
pu: PortUnion{{65535, 65535}},
|
||||
want: []uint16{65535},
|
||||
},
|
||||
{
|
||||
name: "port range with 65535",
|
||||
pu: PortUnion{{65530, 65535}},
|
||||
want: []uint16{65530, 65531, 65532, 65533, 65534, 65535},
|
||||
},
|
||||
{
|
||||
name: "multiple ports and ranges with 65535",
|
||||
pu: PortUnion{{65530, 65535}, {1234, 1236}},
|
||||
want: []uint16{65530, 65531, 65532, 65533, 65534, 65535, 1234, 1235, 1236},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.pu.Ports(); !slices.Equal(got, tt.want) {
|
||||
t.Errorf("PortUnion.Ports() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue