-
Notifications
You must be signed in to change notification settings - Fork 16
/
port_test.go
62 lines (56 loc) · 1.86 KB
/
port_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package goflags
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestPortType(t *testing.T) {
port := &Port{}
_ = port.Set("21-25,80,TCP:443")
require.ElementsMatch(t, port.AsPorts(), []int{21, 22, 23, 24, 25, 80, 443}, "could not get correct ports")
t.Run("comma-separated", func(t *testing.T) {
port := &Port{}
_ = port.Set("80,443")
require.ElementsMatch(t, port.AsPorts(), []int{80, 443}, "could not get correct ports")
})
t.Run("dash", func(t *testing.T) {
port := &Port{}
_ = port.Set("21-25")
require.ElementsMatch(t, port.AsPorts(), []int{21, 22, 23, 24, 25}, "could not get correct ports")
})
t.Run("dash-suffix", func(t *testing.T) {
port := &Port{}
_ = port.Set("1-")
require.Len(t, port.AsPorts(), 65535, "could not get correct ports")
})
t.Run("full", func(t *testing.T) {
port := &Port{}
_ = port.Set("full")
require.Len(t, port.AsPorts(), 65535, "could not get correct ports")
port = &Port{}
_ = port.Set("*")
require.Len(t, port.AsPorts(), 65535, "could not get correct ports")
})
t.Run("top-xxx", func(t *testing.T) {
port := &Port{}
_ = port.Set("top-100")
require.Len(t, port.AsPorts(), 100, "could not get correct ports")
port = &Port{}
_ = port.Set("top-1000")
require.Len(t, port.AsPorts(), 1000, "could not get correct ports")
})
t.Run("services", func(t *testing.T) {
port := &Port{}
_ = port.Set("http,ftp")
require.ElementsMatch(t, port.AsPorts(), []int{80, 8008, 21}, "could not get correct ports")
})
t.Run("services-wildcard", func(t *testing.T) {
port := &Port{}
_ = port.Set("ftp*")
require.ElementsMatch(t, port.AsPorts(), []int{21, 20, 989, 990, 574, 8021}, "could not get correct ports")
})
t.Run("colon", func(t *testing.T) {
port := &Port{}
_ = port.Set("TCP:443,UDP:53")
require.ElementsMatch(t, port.AsPorts(), []int{443, 53}, "could not get correct ports")
})
}