-
Notifications
You must be signed in to change notification settings - Fork 18
/
handlers_test.go
60 lines (48 loc) · 1.14 KB
/
handlers_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
package main
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"github.com/stayradiated/rango/rangolib"
"github.com/stretchr/testify/suite"
)
var (
server *httptest.Server
contentDir string = "__tmp__"
)
type HandlersTestSuite struct {
suite.Suite
}
func (assert *HandlersTestSuite) SetupTest() {
os.Mkdir(contentDir, 0755)
server = httptest.NewServer(NewRouter(&RouterConfig{
Handlers: &Handlers{
Config: rangolib.NewConfig("config.toml"),
Dir: rangolib.NewDir(),
Page: rangolib.NewPage(),
ContentDir: contentDir,
},
AdminDir: "./admin/dist",
}))
}
func (assert *HandlersTestSuite) TearDownTest() {
os.RemoveAll(contentDir)
server.Close()
}
func (assert *HandlersTestSuite) TestReadDir() {
url := server.URL + "/api/dir/"
reader := strings.NewReader("")
req, _ := http.NewRequest("GET", url, reader)
res, err := http.DefaultClient.Do(req)
assert.Nil(err)
assert.Equal(res.StatusCode, http.StatusOK)
var body readDirResponse
err = json.NewDecoder(res.Body).Decode(&body)
assert.Nil(err)
}
func TestHandlers(t *testing.T) {
suite.Run(t, new(HandlersTestSuite))
}