-
Notifications
You must be signed in to change notification settings - Fork 6
/
fs_local_test.go
51 lines (42 loc) · 1.26 KB
/
fs_local_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package noodle
import (
"net/http"
"net/http/httptest"
"testing"
asst "github.com/stretchr/testify/assert"
"github.com/dyweb/gommon/util/testutil"
)
func TestNewLocal(t *testing.T) {
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(NewLocal(".")))
srv := httptest.NewServer(mux)
defer srv.Close()
c := srv.Client()
t.Run("can access file", func(t *testing.T) {
assert := asst.New(t)
assert.Equal(testutil.ReadFixture(t, "README.md"),
testutil.GetBody(t, c, srv.URL+"/README.md"))
})
t.Run("can NOT read dir", func(t *testing.T) {
assert := asst.New(t)
assert.Equal("404 page not found\n", string(testutil.GetBody(t, c, srv.URL+"/doc")))
})
}
func TestNewLocalUnsafe(t *testing.T) {
mux := http.NewServeMux()
mux.Handle("/", http.FileServer(NewLocalUnsafe(".")))
srv := httptest.NewServer(mux)
defer srv.Close()
c := srv.Client()
t.Run("can access file", func(t *testing.T) {
assert := asst.New(t)
assert.Equal(testutil.ReadFixture(t, "README.md"),
testutil.GetBody(t, c, srv.URL+"/README.md"))
})
t.Run("can read dir", func(t *testing.T) {
assert := asst.New(t)
b := testutil.GetBody(t, c, srv.URL+"/doc")
assert.NotEqual("404 page not found\n", string(b))
assert.Contains(string(b), `<a href="README.md">README.md</a>`)
})
}