@@ -32,6 +32,7 @@ var _ = Describe("api2go with gingonic router adapter", func() {
32
32
contextKey = "userID"
33
33
contextValue * string
34
34
apiContext api2go.APIContext
35
+ userStorage * storage.UserStorage
35
36
)
36
37
37
38
BeforeSuite (func () {
@@ -50,7 +51,7 @@ var _ = Describe("api2go with gingonic router adapter", func() {
50
51
return & apiContext
51
52
})
52
53
53
- userStorage : = storage .NewUserStorage ()
54
+ userStorage = storage .NewUserStorage ()
54
55
chocStorage := storage .NewChocolateStorage ()
55
56
api .AddResource (model.User {}, resource.UserResource {ChocStorage : chocStorage , UserStorage : userStorage })
56
57
@@ -164,6 +165,53 @@ var _ = Describe("api2go with gingonic router adapter", func() {
164
165
})
165
166
})
166
167
168
+ Context ("PaginatedFindAll Test" , func () {
169
+ It ("will create links data without double slashes" , func () {
170
+
171
+ userStorage .Insert (model.User {ID : "1" , Username : "Bender Bending Rodriguez" })
172
+ userStorage .Insert (model.User {ID : "2" , Username : "Calculon" })
173
+
174
+ req , err := http .NewRequest ("GET" , "/api/users?page[offset]=0&page[limit]=1" , nil )
175
+
176
+ Expect (err ).To (BeNil ())
177
+
178
+ gg .ServeHTTP (rec , req )
179
+
180
+ expectedResult := `
181
+ {
182
+ "links": {
183
+ "last": "/api/users?page[limit]=1\u0026page[offset]=1",
184
+ "next": "/api/users?page[limit]=1\u0026page[offset]=1"
185
+ },
186
+ "data": [
187
+ {
188
+ "type": "users",
189
+ "id": "2",
190
+ "attributes": {
191
+ "user-name": "Bender Bending Rodriguez"
192
+ },
193
+ "relationships": {
194
+ "sweets": {
195
+ "links": {
196
+ "related": "/api/users/2/sweets",
197
+ "self": "/api/users/2/relationships/sweets"
198
+ },
199
+ "data": []
200
+ }
201
+ }
202
+ }
203
+ ],
204
+ "meta": {
205
+ "author": "The api2go examples crew",
206
+ "license": "wtfpl",
207
+ "license-url": "http://www.wtfpl.net"
208
+ }
209
+ }`
210
+
211
+ Expect (string (rec .Body .Bytes ())).To (MatchJSON (expectedResult ))
212
+ })
213
+ })
214
+
167
215
Context ("Gin Context Key Copy Tests" , func () {
168
216
BeforeEach (func () {
169
217
contextValue = nil
0 commit comments