-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathoption_test.go
114 lines (108 loc) · 2.32 KB
/
option_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
114
package patron
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/mantzas/patron/sync/http"
)
func TestRoutes(t *testing.T) {
type args struct {
rr []http.Route
}
tests := []struct {
name string
args args
wantErr bool
}{
{"failure due to empty routes", args{rr: []http.Route{}}, true},
{"failure due to nil routes", args{rr: nil}, true},
{"success", args{rr: []http.Route{http.NewRoute("/", "GET", nil, true, nil)}}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s, err := New("test", "1.0.0")
assert.NoError(t, err)
err = Routes(tt.args.rr)(s)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
func TestHealthCheck(t *testing.T) {
type args struct {
hcf http.HealthCheckFunc
}
tests := []struct {
name string
args args
wantErr bool
}{
{"failure due to nil health check", args{hcf: nil}, true},
{"success", args{hcf: http.DefaultHealthCheck}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s, err := New("test", "1.0.0")
assert.NoError(t, err)
err = HealthCheck(tt.args.hcf)(s)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
func TestComponents(t *testing.T) {
type args struct {
c Component
}
tests := []struct {
name string
args args
wantErr bool
}{
{"failure due to empty components", args{}, true},
{"failure due to nil components", args{c: nil}, true},
{"success", args{c: &testComponent{}}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s, err := New("test", "1.0.0")
assert.NoError(t, err)
err = Components(tt.args.c)(s)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}
func TestDocs(t *testing.T) {
type args struct {
file string
}
tests := []struct {
name string
args args
wantErr bool
}{
{name: "success", args: args{file: "testdata/test.md"}, wantErr: false},
{name: "doc file missing", args: args{file: ""}, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s, err := New("test", "1.0.0")
assert.NoError(t, err)
err = Docs(tt.args.file)(s)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}