@@ -636,3 +636,85 @@ func TestDirFSServeFileDirectoryRedirect(t *testing.T) {
636
636
t .Fatalf ("Unexpected status code %d for file '/fs.go'. Expecting %d." , ctx .Response .StatusCode (), StatusOK )
637
637
}
638
638
}
639
+
640
+ func TestFSFSGenerateIndexOsDirFS (t * testing.T ) {
641
+ t .Parallel ()
642
+
643
+ t .Run ("dirFS" , func (t * testing.T ) {
644
+ t .Parallel ()
645
+
646
+ fs := & FS {
647
+ FS : dirTestFilesystem ,
648
+ Root : "." ,
649
+ GenerateIndexPages : true ,
650
+ }
651
+ h := fs .NewRequestHandler ()
652
+
653
+ var ctx RequestCtx
654
+ var req Request
655
+ ctx .Init (& req , nil , nil )
656
+
657
+ h (& ctx )
658
+
659
+ cases := []string {"/" , "//" , "" }
660
+ for _ , c := range cases {
661
+ ctx .Request .Reset ()
662
+ ctx .Response .Reset ()
663
+
664
+ req .Header .SetMethod (MethodGet )
665
+ req .SetRequestURI ("http://foobar.com" + c )
666
+ h (& ctx )
667
+
668
+ if ctx .Response .StatusCode () != StatusOK {
669
+ t .Fatalf ("unexpected status code %d for path %q. Expecting %d" , ctx .Response .StatusCode (), ctx .Response .StatusCode (), StatusOK )
670
+ }
671
+
672
+ if ! bytes .Contains (ctx .Response .Body (), []byte ("fasthttputil" )) {
673
+ t .Fatalf ("unexpected body %q. Expecting to contain %q" , ctx .Response .Body (), "fasthttputil" )
674
+ }
675
+
676
+ if ! bytes .Contains (ctx .Response .Body (), []byte ("fs.go" )) {
677
+ t .Fatalf ("unexpected body %q. Expecting to contain %q" , ctx .Response .Body (), "fs.go" )
678
+ }
679
+ }
680
+ })
681
+
682
+ t .Run ("embedFS" , func (t * testing.T ) {
683
+ t .Parallel ()
684
+
685
+ fs := & FS {
686
+ FS : fsTestFilesystem ,
687
+ Root : "." ,
688
+ GenerateIndexPages : true ,
689
+ }
690
+ h := fs .NewRequestHandler ()
691
+
692
+ var ctx RequestCtx
693
+ var req Request
694
+ ctx .Init (& req , nil , nil )
695
+
696
+ h (& ctx )
697
+
698
+ cases := []string {"/" , "//" , "" }
699
+ for _ , c := range cases {
700
+ ctx .Request .Reset ()
701
+ ctx .Response .Reset ()
702
+
703
+ req .Header .SetMethod (MethodGet )
704
+ req .SetRequestURI ("http://foobar.com" + c )
705
+ h (& ctx )
706
+
707
+ if ctx .Response .StatusCode () != StatusOK {
708
+ t .Fatalf ("unexpected status code %d for path %q. Expecting %d" , ctx .Response .StatusCode (), ctx .Response .StatusCode (), StatusOK )
709
+ }
710
+
711
+ if ! bytes .Contains (ctx .Response .Body (), []byte ("fasthttputil" )) {
712
+ t .Fatalf ("unexpected body %q. Expecting to contain %q" , ctx .Response .Body (), "fasthttputil" )
713
+ }
714
+
715
+ if ! bytes .Contains (ctx .Response .Body (), []byte ("fs.go" )) {
716
+ t .Fatalf ("unexpected body %q. Expecting to contain %q" , ctx .Response .Body (), "fs.go" )
717
+ }
718
+ }
719
+ })
720
+ }
0 commit comments