forked from beeryardtech/tmux-net-speed
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathhelpers.test.sh
More file actions
executable file
·137 lines (110 loc) · 2.61 KB
/
helpers.test.sh
File metadata and controls
executable file
·137 lines (110 loc) · 2.61 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash -
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPTS="$CURRENT_DIR/../../scripts"
source "$CURRENT_DIR/../test_utils.sh"
##
# Description:
# General setup before each test
##
setup()
{
source "$SCRIPTS/helpers.sh"
}
##
# get_tmux_option
##
setup_get_tmux_option()
{
setup
## Set generic property
tmux set @get_tmux_option_name "get_tmux_option_val"
}
cleanup_get_tmux_option()
{
# Unset value
tmux set -u @get_tmux_option_name
}
test_get_tmux_option()
{
##
# Should return set value
##
setup_get_tmux_option
result=$( get_tmux_option "@get_tmux_option_name")
assertEqual "$result" "get_tmux_option_val" "should get tmux prop when given no default" -v
cleanup_get_tmux_option
##
# Should show set value
##
setup_get_tmux_option
result=$( get_tmux_option "@get_tmux_option_name_unset")
assertEqual "$result" "" "should get empty string when tmux prop unset"
cleanup_get_tmux_option
##
# Should show set value
##
setup_get_tmux_option
result=$( get_tmux_option @get_tmux_option_name_unset my_default)
assertEqual "$result" "my_default" "should get default if provided for unset prop"
cleanup_get_tmux_option
}
##
# get_velocity
##
setup_get_velocity()
{
setup
}
cleanup_get_velocity() { :; }
test_get_velocity()
{
setup_get_velocity
let input=200
result=$(get_velocity $input 0)
assertEqual "$result" "200 B/s" "should show B/s"
cleanup_get_velocity
setup_get_velocity
let input=2*1024
result=$(get_velocity $input 0)
assertEqual "$result" "2 KB/s" "should show KB/s"
cleanup_get_velocity
setup_get_velocity
let input=3*1048576
result=$(get_velocity $input 0)
assertEqual "$result" "3 MB/s" "should show MB/s"
cleanup_get_velocity
setup_get_velocity
let subtract_from=100*1048576
let subtract_with=50*1048576
result=$(get_velocity $subtract_from subtract_with)
assertEqual "$result" "50 MB/s" "should show MB/s if subraction done"
cleanup_get_velocity
}
##
# get_interfaces
##
setup_get_interfaces()
{
setup
}
cleanup_get_interfaces() { :; }
test_get_interfaces()
{
setup_get_interfaces
result=$(get_interfaces)
if [[ -n is_osx ]]
then
assertEqual "$result" "en0 en1 en2 en3 en4 en5 en7" "should output space-delimited list of interfaces" -v
else
assertEqual "$result" "eth0 lo wlan0" "should output space-delimited list of interfaces" -v
fi
cleanup_get_interfaces
}
suites()
{
#test_get_tmux_option
#test_get_velocity
test_get_interfaces
}
# Run tests
suites