-
Notifications
You must be signed in to change notification settings - Fork 2
/
options_test.go
95 lines (89 loc) · 1.76 KB
/
options_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
package gmeter
import (
"io"
"io/ioutil"
"net/url"
"reflect"
"testing"
)
func TestGetOptions(t *testing.T) {
type args struct {
arguments []string
stdout io.Writer
stderr io.Writer
exit exitFunc
}
tests := []struct {
name string
args func(t *testing.T) args
want1 Options
}{
{
name: "show help",
args: func(t *testing.T) args {
return args{
arguments: []string{"-h"},
exit: func(code int) {
if code != 0 {
t.Errorf("got non-zero exit code: %d", code)
}
t.Skip()
},
}
},
},
{
name: "no target",
args: func(t *testing.T) args {
return args{
arguments: []string{""},
stderr: ioutil.Discard,
exit: func(code int) {
if code != 2 {
t.Errorf("unexpected exit code, got: %d, want: 2", code)
}
t.Skip()
},
}
},
},
{
name: "bad target",
args: func(t *testing.T) args {
return args{
arguments: []string{"-t", "::"},
stderr: ioutil.Discard,
exit: func(code int) {
if code != 2 {
t.Errorf("unexpected exit code, got: %d, want: 2", code)
}
t.Skip()
},
}
},
},
{
name: "success",
args: func(t *testing.T) args {
return args{
arguments: []string{"-t", "http://github.com"},
}
},
want1: Options{
CassettePath: ".",
Insecure: false,
ListenAddress: "localhost:8080",
TargetURL: &url.URL{Scheme: "http", Host: "github.com"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tArgs := tt.args(t)
got1 := GetOptions(tArgs.arguments, tArgs.stdout, tArgs.stderr, tArgs.exit)
if !reflect.DeepEqual(got1, tt.want1) {
t.Errorf("GetOptions got1 = %v, want1: %v", got1, tt.want1)
}
})
}
}