@@ -475,12 +475,6 @@ func TestDirJoin(t *testing.T) {
475
475
test (Dir ("/etc" ), "/hosts" )
476
476
test (Dir ("/etc" ), "hosts" )
477
477
test (Dir ("/etc" ), "../../../../hosts" )
478
-
479
- // Not really directories, but since we use this trick in
480
- // ServeFile, test it:
481
- test (Dir ("/etc/hosts" ), "" )
482
- test (Dir ("/etc/hosts" ), "/" )
483
- test (Dir ("/etc/hosts" ), "../" )
484
478
}
485
479
486
480
func TestEmptyDirOpenCWD (t * testing.T ) {
@@ -497,6 +491,15 @@ func TestEmptyDirOpenCWD(t *testing.T) {
497
491
test (Dir ("./" ))
498
492
}
499
493
494
+ // issue 63769
495
+ func TestDirNormalFile (t * testing.T ) {
496
+ f , err := Dir ("testdata/index.html" ).Open ("" )
497
+ if err == nil {
498
+ f .Close ()
499
+ t .Fatalf ("got nil, want error" )
500
+ }
501
+ }
502
+
500
503
func TestServeFileContentType (t * testing.T ) { run (t , testServeFileContentType ) }
501
504
func testServeFileContentType (t * testing.T , mode testMode ) {
502
505
const ctype = "icecream/chocolate"
@@ -1672,24 +1675,15 @@ func (grw gzipResponseWriter) Flush() {
1672
1675
// Issue 63769
1673
1676
func TestFileServerDirWithRootFile (t * testing.T ) { run (t , testFileServerDirWithRootFile ) }
1674
1677
func testFileServerDirWithRootFile (t * testing.T , mode testMode ) {
1675
- filename := "index.html"
1676
- contents , err := os .ReadFile ("testdata/index.html" )
1677
- if err != nil {
1678
- t .Fatal (err )
1679
- }
1680
1678
ts := newClientServerTest (t , mode , FileServer (Dir ("testdata/index.html" ))).ts
1681
1679
defer ts .Close ()
1682
1680
1683
1681
res , err := ts .Client ().Get (ts .URL )
1684
1682
if err != nil {
1685
1683
t .Fatal (err )
1686
1684
}
1687
- b , err := io .ReadAll (res .Body )
1688
- if err != nil {
1689
- t .Fatal ("reading Body:" , err )
1690
- }
1691
- if s := string (b ); s != string (contents ) {
1692
- t .Errorf ("for path %q got %q, want %q" , filename , s , contents )
1685
+ if s := res .StatusCode ; s != StatusInternalServerError {
1686
+ t .Errorf ("got %q, want 500" , s )
1693
1687
}
1694
1688
res .Body .Close ()
1695
1689
}
0 commit comments