@@ -16,6 +16,7 @@ import (
16
16
"aahframework.org/config.v0"
17
17
"aahframework.org/essentials.v0"
18
18
"aahframework.org/test.v0/assert"
19
+ "aahframework.org/vfs.v0"
19
20
)
20
21
21
22
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
@@ -402,10 +403,7 @@ func TestRouterConfigNotExists(t *testing.T) {
402
403
}
403
404
404
405
func TestRouterNamespaceConfig (t * testing.T ) {
405
- wd , _ := os .Getwd ()
406
- appCfg , _ := config .ParseString ("" )
407
- router := New (filepath .Join (wd , "testdata" , "routes-namespace.conf" ), appCfg )
408
- err := router .Load ()
406
+ router , err := createRouter ("routes-namespace.conf" )
409
407
assert .FailNowOnError (t , err , "" )
410
408
411
409
routes := router .Domains ["localhost:8080" ].routes
@@ -418,18 +416,14 @@ func TestRouterNamespaceConfig(t *testing.T) {
418
416
assert .Equal (t , "GET" , routes ["disable_user" ].Method )
419
417
assert .Equal (t , "form" , routes ["disable_user" ].Auth )
420
418
421
- router = New ( filepath . Join ( wd , "testdata" , "routes-namespace-action-error.conf" ), appCfg )
422
- err = router . Load ( )
419
+ // Error
420
+ _ , err = createRouter ( "routes-namespace-action-error.conf" )
423
421
assert .NotNil (t , err )
424
422
assert .Equal (t , "'list_users.action' key is missing, it seems to be multiple HTTP methods" , err .Error ())
425
423
}
426
424
427
425
func TestRouterNamespaceSimplifiedConfig (t * testing.T ) {
428
-
429
- wd , _ := os .Getwd ()
430
- appCfg , _ := config .ParseString ("" )
431
- router := New (filepath .Join (wd , "testdata" , "routes-simplified.conf" ), appCfg )
432
- err := router .Load ()
426
+ router , err := createRouter ("routes-simplified.conf" )
433
427
assert .FailNowOnError (t , err , "" )
434
428
435
429
routes := router .Domains ["localhost:8080" ].routes
@@ -450,11 +444,7 @@ func TestRouterNamespaceSimplifiedConfig(t *testing.T) {
450
444
}
451
445
452
446
func TestRouterNamespaceSimplified2Config (t * testing.T ) {
453
-
454
- wd , _ := os .Getwd ()
455
- appCfg , _ := config .ParseString ("" )
456
- router := New (filepath .Join (wd , "testdata" , "routes-simplified-2.conf" ), appCfg )
457
- err := router .Load ()
447
+ router , err := createRouter ("routes-simplified-2.conf" )
458
448
assert .FailNowOnError (t , err , "" )
459
449
460
450
routes := router .Domains ["localhost:8080" ].routes
@@ -474,18 +464,13 @@ func TestRouterNamespaceSimplified2Config(t *testing.T) {
474
464
assert .Equal (t , "gt=1,lt=10" , rule )
475
465
476
466
// Error
477
- router = New (filepath .Join (wd , "testdata" , "routes-simplified-2-error.conf" ), appCfg )
478
- err = router .Load ()
467
+ _ , err = createRouter ("routes-simplified-2-error.conf" )
479
468
assert .NotNil (t , err )
480
469
assert .Equal (t , "'routes.path' has invalid validation rule '/v1/users/:id gt=1,lt=10]'" , err .Error ())
481
470
}
482
471
483
472
func TestRouterStaticSectionBaseDirForFilePaths (t * testing.T ) {
484
-
485
- wd , _ := os .Getwd ()
486
- appCfg , _ := config .ParseString ("" )
487
- router := New (filepath .Join (wd , "testdata" , "routes-static.conf" ), appCfg )
488
- err := router .Load ()
473
+ router , err := createRouter ("routes-static.conf" )
489
474
assert .FailNowOnError (t , err , "" )
490
475
491
476
// Assertion
@@ -506,17 +491,13 @@ func TestRouterStaticSectionBaseDirForFilePaths(t *testing.T) {
506
491
assert .Equal (t , "robots.txt" , robotTxtRoute .File )
507
492
508
493
// ERROR missing values
509
- router = New (filepath .Join (wd , "testdata" , "routes-static-base-dir-missing.conf" ), appCfg )
510
- err = router .Load ()
494
+ _ , err = createRouter ("routes-static-base-dir-missing.conf" )
511
495
assert .NotNil (t , err )
512
496
assert .Equal (t , "'static.favicon.base_dir' value is missing" , err .Error ())
513
497
}
514
498
515
499
func TestRouterWebSocketConfig (t * testing.T ) {
516
- wd , _ := os .Getwd ()
517
- appCfg , _ := config .ParseString ("" )
518
- router := New (filepath .Join (wd , "testdata" , "routes-websocket.conf" ), appCfg )
519
- err := router .Load ()
500
+ router , err := createRouter ("routes-websocket.conf" )
520
501
assert .FailNowOnError (t , err , "" )
521
502
522
503
routes := router .Domains ["localhost:8080" ].routes
@@ -538,17 +519,20 @@ func TestRouterWebSocketConfig(t *testing.T) {
538
519
}
539
520
540
521
func createRouter (filename string ) (* Router , error ) {
522
+ fs := new (vfs.VFS )
523
+ fs .AddMount ("/app/config" , testdataBaseDir ())
541
524
542
- wd , _ := os .Getwd ()
543
525
appCfg , _ := config .ParseString (`routes {
544
526
localhost {
545
527
host = "localhost"
546
528
port = "8080"
547
529
}
548
530
}` )
549
531
550
- router := New (filepath .Join (wd , "testdata" , filename ), appCfg )
532
+ router := New ("/app/config/" + filename , appCfg )
533
+ router .vfs = fs
551
534
err := router .Load ()
535
+
552
536
return router , err
553
537
}
554
538
@@ -563,3 +547,11 @@ func createHTTPRequest(host, path string) *http.Request {
563
547
564
548
return req
565
549
}
550
+
551
+ func testdataBaseDir () string {
552
+ wd , _ := os .Getwd ()
553
+ if idx := strings .Index (wd , "testdata" ); idx > 0 {
554
+ wd = wd [:idx ]
555
+ }
556
+ return filepath .Join (wd , "testdata" )
557
+ }
0 commit comments