forked from pouriyajamshidi/tcping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcping_test.go
113 lines (109 loc) · 2.11 KB
/
tcping_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCalcTime(t *testing.T) {
type args struct {
time uint
}
tests := []struct {
name string
args args
want string
}{
{
name: "1 second",
args: args{1},
want: "1 second",
},
{
name: "59 seconds",
args: args{59},
want: "59 seconds",
},
{
name: "1 minute",
args: args{1 * 60},
want: "1 minute",
},
{
name: "59 minutes 0 seconds",
args: args{59 * 60},
want: "59 minutes 0 seconds",
},
{
name: "1 minute 5 seconds",
args: args{1*60 + 5},
want: "1 minute 5 seconds",
},
{
name: "59 minutes 5 seconds",
args: args{59*60 + 5},
want: "59 minutes 5 seconds",
},
{
name: "1 hour",
args: args{1 * 60 * 60},
want: "1 hour",
},
{
name: "1 hour 10 minutes 5 seconds",
args: args{1*60*60 + 10*60 + 5},
want: "1 hour 10 minutes 5 seconds",
},
{
name: "59 hours 0 minutes 0 seconds",
args: args{59 * 60 * 60},
want: "59 hours 0 minutes 0 seconds",
},
{
name: "59 hours 10 minutes 5 seconds",
args: args{59*60*60 + 10*60 + 5},
want: "59 hours 10 minutes 5 seconds",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := calcTime(tt.args.time); got != tt.want {
t.Errorf("calcTime() = %v, want %v", got, tt.want)
}
})
}
}
func TestPermuteArgs(t *testing.T) {
type args struct {
args []string
}
tests := []struct {
name string
args args
want []string
}{
{
"host/ip before option",
args{args: []string{"127.0.0.1", "8080", "-r", "3"}},
[]string{"-r", "3", "127.0.0.1", "8080"},
},
{
"host/ip after option",
args{args: []string{"-r", "3", "127.0.0.1", "8080"}},
[]string{"-r", "3", "127.0.0.1", "8080"},
},
{
"check for updates",
args{args: []string{"-u"}},
[]string{"-u"},
},
/**
* cases in which the value of the option does not exist are not listed.
* they call directly usage() and exit with code 1.
*/
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
permuteArgs(tt.args.args)
assert.Equal(t, tt.want, tt.args.args)
})
}
}