-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
57 lines (48 loc) · 1.11 KB
/
main_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
package main
import (
"bytes"
"reflect"
"strings"
"testing"
)
func TestCmdOptions(t *testing.T) {
opts := cmdOptions{
OptAllowedPorts: []int{80, 443},
OptDestinationHost: "www.example.com",
OptDestinationPort: 81,
OptVerbose: true,
}
if !reflect.DeepEqual(opts.AllowedPorts(), []int{80, 443}) {
t.Errorf("got %q", opts.AllowedPorts())
}
if opts.DestinationHost() != "www.example.com" {
t.Errorf("got %q", opts.DestinationHost())
}
if opts.DestinationPort() != 81 {
t.Errorf("got %d", opts.DestinationPort())
}
if opts.Verbose() != true {
t.Errorf("got %q", opts.Verbose())
}
}
func TestRunInvalidArgs(t *testing.T) {
var b bytes.Buffer
Run([]string{"arg"}, &b)
if strings.Index(b.String(), "Usage") == -1 {
t.Errorf("got %q", b.String())
}
}
func TestRunHelp(t *testing.T) {
var b bytes.Buffer
Run([]string{"--help"}, &b)
if strings.Index(b.String(), "Usage") == -1 {
t.Errorf("got %q", b.String())
}
}
func TestRunVersion(t *testing.T) {
var b bytes.Buffer
Run([]string{"--version"}, &b)
if strings.Index(b.String(), "r2proxy:") != 0 {
t.Errorf("got %q", b.String())
}
}