forked from micheartin/docgen-yes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder_test.go
100 lines (79 loc) · 1.71 KB
/
builder_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
package docgen_test
import (
"net/http"
"reflect"
"testing"
"github.com/go-chi/chi/v5"
"github.com/teal-finance/docgen-yes"
)
func TestBuildDoc(t *testing.T) {
t.Parallel()
cases := []struct {
name string
routes chi.Routes
want docgen.Doc
wantErr bool
}{{
name: "empty",
routes: nil,
want: docgen.Doc{},
wantErr: false,
}}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
got, err := docgen.BuildDoc(c.routes)
if (err != nil) != c.wantErr {
t.Errorf("BuildDoc() error = %v, wantErr %v", err, c.wantErr)
return
}
if !reflect.DeepEqual(got, c.want) {
t.Errorf("BuildDoc() = %v, want %v", got, c.want)
}
})
}
}
func Test_buildDocRouter(t *testing.T) {
t.Parallel()
cases := []struct {
name string
routes chi.Routes
want docgen.DocRouter
}{{
name: "empty",
routes: nil, want: docgen.DocRouter{},
}}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
if got := docgen.BuildDocRouter(c.routes); !reflect.DeepEqual(got, c.want) {
t.Errorf("buildDocRouter() = %v, want %v", got, c.want)
}
})
}
}
type next struct{ called bool }
func (n *next) ServeHTTP(http.ResponseWriter, *http.Request) { n.called = true }
func Test_GetFuncInfo(t *testing.T) {
t.Parallel()
cases := []struct {
name string
i any
want docgen.FuncInfo
}{{
name: "Unresolvable",
i: next{},
want: docgen.FuncInfo{Unresolvable: true},
}}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
if got := docgen.GetFuncInfo(c.i); !reflect.DeepEqual(got, c.want) {
t.Errorf("GetFuncInfo() = %v, want %v", got, c.want)
}
})
}
}