@@ -236,7 +236,7 @@ func (s *mockedSwag) ReadDoc() string {
236
236
func TestWrapHandler (t * testing.T ) {
237
237
router := echo .New ()
238
238
239
- router .Any ("/*" , EchoWrapHandler (DocExpansion ("none" ), DomID ("# swagger-ui" )))
239
+ router .Any ("/*" , EchoWrapHandler (DocExpansion ("none" ), DomID ("swagger-ui" )))
240
240
241
241
w1 := performRequest (http .MethodGet , "/index.html" , router )
242
242
assert .Equal (t , http .StatusOK , w1 .Code )
@@ -277,6 +277,37 @@ func TestWrapHandler(t *testing.T) {
277
277
278
278
}
279
279
280
+ func TestConfig (t * testing.T ) {
281
+ router := echo .New ()
282
+
283
+ swaggerHandler := URL ("swagger.json" )
284
+ router .Any ("/*" , EchoWrapHandler (swaggerHandler ))
285
+
286
+ w := performRequest ("GET" , "/index.html" , router )
287
+ assert .Equal (t , 200 , w .Code )
288
+ assert .Contains (t , w .Body .String (), `url: "swagger.json"` )
289
+ }
290
+
291
+ func TestConfigWithOAuth (t * testing.T ) {
292
+ router := echo .New ()
293
+
294
+ swaggerHandler := EchoWrapHandler (OAuth (& OAuthConfig {
295
+ ClientId : "my-client-id" ,
296
+ Realm : "my-realm" ,
297
+ AppName : "My App Name" ,
298
+ }))
299
+ router .GET ("/*" , swaggerHandler )
300
+
301
+ w := performRequest ("GET" , "/index.html" , router )
302
+ assert .Equal (t , 200 , w .Code )
303
+ body := w .Body .String ()
304
+ assert .Contains (t , body , `ui.initOAuth({
305
+ clientId: "my-client-id",
306
+ realm: "my-realm",
307
+ appName: "My App Name"
308
+ })` )
309
+ }
310
+
280
311
func TestHandlerReuse (t * testing.T ) {
281
312
router := echo .New ()
282
313
@@ -352,7 +383,7 @@ func TestDocExpansion(t *testing.T) {
352
383
353
384
func TestDomID (t * testing.T ) {
354
385
var cfg Config
355
- expected := "# swagger-ui"
386
+ expected := "swagger-ui"
356
387
DomID (expected )(& cfg )
357
388
assert .Equal (t , expected , cfg .DomID )
358
389
}
@@ -374,3 +405,23 @@ func TestPersistAuthorization(t *testing.T) {
374
405
PersistAuthorization (expected )(& cfg )
375
406
assert .Equal (t , expected , cfg .PersistAuthorization )
376
407
}
408
+
409
+ func TestOAuth (t * testing.T ) {
410
+ var cfg Config
411
+ expected := OAuthConfig {
412
+ ClientId : "my-client-id" ,
413
+ Realm : "my-realm" ,
414
+ AppName : "My App Name" ,
415
+ }
416
+ OAuth (& expected )(& cfg )
417
+ assert .Equal (t , expected .ClientId , cfg .OAuth .ClientId )
418
+ assert .Equal (t , expected .Realm , cfg .OAuth .Realm )
419
+ assert .Equal (t , expected .AppName , cfg .OAuth .AppName )
420
+ }
421
+
422
+ func TestOAuthNil (t * testing.T ) {
423
+ var cfg Config
424
+ var expected * OAuthConfig
425
+ OAuth (expected )(& cfg )
426
+ assert .Equal (t , expected , cfg .OAuth )
427
+ }
0 commit comments