-
Notifications
You must be signed in to change notification settings - Fork 35
/
args_test.go
55 lines (50 loc) · 1.59 KB
/
args_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
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestParseArgsDefault(t *testing.T) {
cfg, err := parseArgs([]string{"localhost:80"})
assert.Nil(t, err)
assert.Equal(t, cfg.DestAddr, "localhost:80")
assert.Equal(t, cfg.Port, 8000)
assert.Equal(t, 0xffff+1, cfg.BufferSize)
assert.Equal(t, time.Millisecond*5, cfg.Latency.Base)
assert.Equal(t, time.Duration(0), cfg.Latency.SineAmplitude)
}
func TestParseArgsError(t *testing.T) {
_, err := parseArgs([]string{"--nope", "localhost:80"})
assert.NotNil(t, err)
}
func TestParseArgsAll(t *testing.T) {
cfg, err := parseArgs(
[]string{
"--host=somehost",
"--port=1234",
"--buffer=200B",
"--latency=100ms",
"--sine-amplitude=50ms",
"--sine-period=1m",
"--square-amplitude=123ms",
"--square-period=3m",
"--triangle-amplitude=150ms",
"--triangle-period=2m",
"host:777",
},
)
assert.Nil(t, err)
assert.Equal(t, cfg.DestAddr, "host:777")
assert.Equal(t, cfg.Host, "somehost")
assert.Equal(t, cfg.Port, 1234)
assert.Equal(t, 200, cfg.BufferSize)
assert.Equal(t, time.Millisecond*100, cfg.Latency.Base)
assert.Equal(t, time.Millisecond*50, cfg.Latency.SineAmplitude)
assert.Equal(t, time.Minute, cfg.Latency.SinePeriod)
assert.Equal(t, time.Duration(0), cfg.Latency.SawAmplitude)
assert.Equal(t, time.Duration(0), cfg.Latency.SawPeriod)
assert.Equal(t, time.Millisecond*123, cfg.Latency.SquareAmplitude)
assert.Equal(t, time.Minute*3, cfg.Latency.SquarePeriod)
assert.Equal(t, time.Millisecond*150, cfg.Latency.TriangleAmplitude)
assert.Equal(t, time.Minute*2, cfg.Latency.TrianglePeriod)
}