-
Notifications
You must be signed in to change notification settings - Fork 43
/
static_test.go
65 lines (48 loc) · 1.42 KB
/
static_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package neo
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestServe(t *testing.T) {
static := Static{}
static.init()
assert.NotNil(t, static.serving)
static.Serve("/some/url", "./testassets")
abs, err := filepath.Abs("./testassets")
assert.Nil(t, err)
match, err := static.match("/some/url/test.txt")
assert.Nil(t, err)
assert.Exactly(t, abs+"/test.txt", match)
match, err = static.match("/some/unknown/url")
assert.NotNil(t, err)
assert.Equal(t, "", match)
}
func TestCanBeServed(t *testing.T) {
static := Static{}
static.init()
assert.NotNil(t, static.serving)
static.Serve("/some/url", "./testassets")
abs, err := filepath.Abs("./testassets")
assert.Nil(t, err)
assert.False(t, static.canBeServed(abs))
assert.True(t, static.canBeServed(abs+"/index.html"))
assert.False(t, static.canBeServed(abs+"/unknown.html"))
}
func TestServeIndexPages(t *testing.T) {
static := Static{}
static.init()
static.Serve("/", "./testassets")
abs, err := filepath.Abs("./testassets")
// it should server index.html inside main directory
match, err := static.match("/")
assert.Nil(t, err)
assert.Exactly(t, abs+"/index.html", match)
// it should serve index.html inside child directories
match, err = static.match("/dir")
assert.Nil(t, err)
assert.Exactly(t, abs+"/dir/index.html", match)
// it should not server index.tpl
match, err = static.match("/templates")
assert.NotNil(t, err)
}