@@ -11,6 +11,7 @@ import (
1111
1212 simplapi "github.com/go-simpl/simplapi"
1313 "github.com/go-simpl/simplapi/pkg/context"
14+ "github.com/go-simpl/simplapi/tests/utils"
1415
1516 _ "github.com/go-simpl/simplapi/pkg/framework/fiberframework"
1617)
@@ -24,142 +25,163 @@ func (*HelloResponse) GetStatusCode() int {
2425}
2526
2627func TestChainReturnedFromFirstFunc (t * testing.T ) {
27- app := simplapi .New ()
28- fApp := app .GetApp ()
28+ frameworks := utils .GetAllFrameworks ()
29+ for _ , framework := range frameworks {
30+ t .Run (framework , func (t * testing.T ) {
31+ app := simplapi .New (framework , "" )
32+ fApp := app .GetApp ()
2933
30- func1 := func () (* HelloResponse , error ) {
31- return & HelloResponse {Message : "func1" }, nil
32- }
34+ func1 := func () (* HelloResponse , error ) {
35+ return & HelloResponse {Message : "func1" }, nil
36+ }
3337
34- func2 := func () (* HelloResponse , error ) {
35- return & HelloResponse {Message : "func2" }, nil
36- }
38+ func2 := func () (* HelloResponse , error ) {
39+ return & HelloResponse {Message : "func2" }, nil
40+ }
3741
38- app .GET ("/" , func1 , func2 )
39- app .Sync ()
42+ app .GET ("/" , func1 , func2 )
43+ app .Sync ()
4044
41- req , err := http .NewRequest ("GET" , "/" , nil )
42- assert .NoError (t , err )
45+ req , err := http .NewRequest ("GET" , "/" , nil )
46+ assert .NoError (t , err )
4347
44- response , err := fApp .TestRequest (req )
45- assert .NoError (t , err )
48+ response , err := fApp .TestRequest (req )
49+ assert .NoError (t , err )
4650
47- assert .Equal (t , http .StatusOK , response .StatusCode )
51+ assert .Equal (t , http .StatusOK , response .StatusCode )
4852
49- bodyBytes , err := io .ReadAll (response .Body )
50- assert .NoError (t , err )
51- bodyString := string (bodyBytes )
52- assert .Equal (t , `{"message":"func1"}` , bodyString )
53+ bodyBytes , err := io .ReadAll (response .Body )
54+ assert .NoError (t , err )
55+ bodyString := string (bodyBytes )
56+ assert .Equal (t , `{"message":"func1"}` , bodyString )
57+ })
58+ }
5359}
5460
5561func TestChainReturnedFromSecondFunc (t * testing.T ) {
56- app := simplapi .New ()
57- fApp := app .GetApp ()
62+ frameworks := utils .GetAllFrameworks ()
63+ for _ , framework := range frameworks {
64+ t .Run (framework , func (t * testing.T ) {
65+ app := simplapi .New (framework , "" )
66+ fApp := app .GetApp ()
5867
59- func1 := func () (* HelloResponse , error ) {
60- return nil , nil
61- }
68+ func1 := func () (* HelloResponse , error ) {
69+ return nil , nil
70+ }
6271
63- func2 := func () (* HelloResponse , error ) {
64- return & HelloResponse {Message : "func2" }, nil
65- }
72+ func2 := func () (* HelloResponse , error ) {
73+ return & HelloResponse {Message : "func2" }, nil
74+ }
6675
67- app .GET ("/" , func1 , func2 )
68- app .Sync ()
76+ app .GET ("/" , func1 , func2 )
77+ app .Sync ()
6978
70- req , err := http .NewRequest ("GET" , "/" , nil )
71- assert .NoError (t , err )
79+ req , err := http .NewRequest ("GET" , "/" , nil )
80+ assert .NoError (t , err )
7281
73- response , err := fApp .TestRequest (req )
74- assert .NoError (t , err )
82+ response , err := fApp .TestRequest (req )
83+ assert .NoError (t , err )
7584
76- assert .Equal (t , http .StatusOK , response .StatusCode )
85+ assert .Equal (t , http .StatusOK , response .StatusCode )
7786
78- bodyBytes , err := io .ReadAll (response .Body )
79- assert .NoError (t , err )
80- bodyString := string (bodyBytes )
81- assert .Equal (t , `{"message":"func2"}` , bodyString )
87+ bodyBytes , err := io .ReadAll (response .Body )
88+ assert .NoError (t , err )
89+ bodyString := string (bodyBytes )
90+ assert .Equal (t , `{"message":"func2"}` , bodyString )
91+ })
92+ }
8293}
8394
8495func TestChainReturnedFromNoFunc (t * testing.T ) {
85- app := simplapi .New ()
86- fApp := app .GetApp ()
96+ frameworks := utils .GetAllFrameworks ()
97+ for _ , framework := range frameworks {
98+ t .Run (framework , func (t * testing.T ) {
99+ app := simplapi .New (framework , "" )
100+ fApp := app .GetApp ()
87101
88- func1 := func () (* HelloResponse , error ) {
89- return nil , nil
90- }
102+ func1 := func () (* HelloResponse , error ) {
103+ return nil , nil
104+ }
91105
92- func2 := func () (* HelloResponse , error ) {
93- return nil , nil
94- }
106+ func2 := func () (* HelloResponse , error ) {
107+ return nil , nil
108+ }
95109
96- app .GET ("/" , func1 , func2 )
97- app .Sync ()
110+ app .GET ("/" , func1 , func2 )
111+ app .Sync ()
98112
99- req , err := http .NewRequest ("GET" , "/" , nil )
100- assert .NoError (t , err )
113+ req , err := http .NewRequest ("GET" , "/" , nil )
114+ assert .NoError (t , err )
101115
102- response , err := fApp .TestRequest (req )
103- assert .NoError (t , err )
116+ response , err := fApp .TestRequest (req )
117+ assert .NoError (t , err )
104118
105- assert .Equal (t , http .StatusOK , response .StatusCode )
119+ assert .Equal (t , http .StatusOK , response .StatusCode )
120+ })
121+ }
106122}
107123
108124func TestChainReturnedErrorFromFirstFunc (t * testing.T ) {
109- app := simplapi .New ()
110- fApp := app .GetApp ()
125+ frameworks := utils .GetAllFrameworks ()
126+ for _ , framework := range frameworks {
127+ t .Run (framework , func (t * testing.T ) {
128+ app := simplapi .New (framework , "" )
129+ fApp := app .GetApp ()
111130
112- func1 := func () (* HelloResponse , error ) {
113- return nil , errors .New ("server error" )
114- }
131+ func1 := func () (* HelloResponse , error ) {
132+ return nil , errors .New ("server error" )
133+ }
115134
116- func2 := func () (* HelloResponse , error ) {
117- return nil , nil
118- }
135+ func2 := func () (* HelloResponse , error ) {
136+ return nil , nil
137+ }
119138
120- app .GET ("/" , func1 , func2 )
121- app .Sync ()
139+ app .GET ("/" , func1 , func2 )
140+ app .Sync ()
122141
123- req , err := http .NewRequest ("GET" , "/" , nil )
124- assert .NoError (t , err )
142+ req , err := http .NewRequest ("GET" , "/" , nil )
143+ assert .NoError (t , err )
125144
126- response , err := fApp .TestRequest (req )
127- assert .NoError (t , err )
145+ response , err := fApp .TestRequest (req )
146+ assert .NoError (t , err )
128147
129- assert .Equal (t , http .StatusInternalServerError , response .StatusCode )
148+ assert .Equal (t , http .StatusInternalServerError , response .StatusCode )
149+ })
150+ }
130151
131- bodyBytes , err := io .ReadAll (response .Body )
132- assert .NoError (t , err )
133- bodyString := string (bodyBytes )
134- assert .Equal (t , `server error` , bodyString )
135152}
136153
137154func TestContextInChain (t * testing.T ) {
138- app := simplapi .New ()
139- fApp := app .GetApp ()
140-
141- func1 := func (ctx * context.Context ) (* HelloResponse , error ) {
142- ctx .Set ("test" , "test" )
143- return nil , nil
144- }
145-
146- func2 := func (ctx * context.Context ) (* HelloResponse , error ) {
147- assert .Equal (t , "test" , ctx .Get ("test" ))
148- ctx .Delete ("test" )
149- return nil , nil
155+ frameworks := utils .GetAllFrameworks ()
156+ for _ , framework := range frameworks {
157+ t .Run (framework , func (t * testing.T ) {
158+ app := simplapi .New (framework , "" )
159+ fApp := app .GetApp ()
160+
161+ func1 := func (ctx * context.Context ) (* HelloResponse , error ) {
162+ ctx .Set ("test" , "test" )
163+ return nil , nil
164+ }
165+
166+ func2 := func (ctx * context.Context ) (* HelloResponse , error ) {
167+ assert .Equal (t , "test" , ctx .Get ("test" ))
168+ ctx .Delete ("test" )
169+ return nil , nil
170+ }
171+
172+ func3 := func (ctx * context.Context ) (* HelloResponse , error ) {
173+ assert .False (t , ctx .Contains ("test" ))
174+ return & HelloResponse {Message : "" }, nil
175+ }
176+
177+ app .GET ("/" , func1 , func2 , func3 )
178+ app .Sync ()
179+
180+ req := httptest .NewRequest ("GET" , "/" , nil )
181+ response , err := fApp .TestRequest (req )
182+ assert .NoError (t , err )
183+
184+ assert .Equal (t , http .StatusOK , response .StatusCode )
185+ })
150186 }
151-
152- func3 := func (ctx * context.Context ) (* HelloResponse , error ) {
153- assert .False (t , ctx .Contains ("test" ))
154- return & HelloResponse {Message : "" }, nil
155- }
156-
157- app .GET ("/" , func1 , func2 , func3 )
158- app .Sync ()
159-
160- req := httptest .NewRequest ("GET" , "/" , nil )
161- response , err := fApp .TestRequest (req )
162- assert .NoError (t , err )
163-
164- assert .Equal (t , http .StatusOK , response .StatusCode )
165187}
0 commit comments