@@ -236,7 +236,7 @@ func (s *mockedSwag) ReadDoc() string {
236236func TestWrapHandler (t * testing.T ) {
237237 router := echo .New ()
238238
239- router .Any ("/*" , EchoWrapHandler (DocExpansion ("none" ), DomID ("# swagger-ui" )))
239+ router .Any ("/*" , EchoWrapHandler (DocExpansion ("none" ), DomID ("swagger-ui" )))
240240
241241 w1 := performRequest (http .MethodGet , "/index.html" , router )
242242 assert .Equal (t , http .StatusOK , w1 .Code )
@@ -277,6 +277,37 @@ func TestWrapHandler(t *testing.T) {
277277
278278}
279279
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+
280311func TestHandlerReuse (t * testing.T ) {
281312 router := echo .New ()
282313
@@ -352,7 +383,7 @@ func TestDocExpansion(t *testing.T) {
352383
353384func TestDomID (t * testing.T ) {
354385 var cfg Config
355- expected := "# swagger-ui"
386+ expected := "swagger-ui"
356387 DomID (expected )(& cfg )
357388 assert .Equal (t , expected , cfg .DomID )
358389}
@@ -374,3 +405,23 @@ func TestPersistAuthorization(t *testing.T) {
374405 PersistAuthorization (expected )(& cfg )
375406 assert .Equal (t , expected , cfg .PersistAuthorization )
376407}
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