-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathsocks_test.go
More file actions
55 lines (48 loc) · 1.09 KB
/
Copy pathsocks_test.go
File metadata and controls
55 lines (48 loc) · 1.09 KB
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
package command
import (
"strings"
"testing"
"time"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
)
func TestSocksCmdDstSubnetError(t *testing.T) {
t.Parallel()
tests := []struct {
name string
args []string
}{
{
name: "RequiredArg",
args: nil,
},
{
name: "InvalidDstSubnet",
args: []string{"invalid_ip_address"},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
cmd := newSocksCmd().cmd
err := cmd.RunE(cmd, tt.args)
require.Error(t, err)
})
}
}
func TestSocksCmdOptsInitCliFlags(t *testing.T) {
t.Parallel()
var opts socksCmdOpts
cmd := &cobra.Command{}
opts.initCliFlags(cmd)
err := cmd.ParseFlags(strings.Split(
"--json -p 23-57,71-2733 -f ip_file.jsonl -w 300 --exit-delay 10s --timeout 2s", " "))
require.NoError(t, err)
require.True(t, opts.json)
require.Equal(t, "23-57,71-2733", opts.rawPortRanges)
require.Equal(t, "ip_file.jsonl", opts.ipFile)
require.Equal(t, 300, opts.workers)
require.Equal(t, 10*time.Second, opts.exitDelay)
require.Equal(t, 2*time.Second, opts.timeout)
}