-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers_test.go
53 lines (44 loc) · 1.11 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
package main
import (
"log"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/restsend/carrot"
"github.com/stretchr/testify/assert"
)
func setupRouter() (*gin.Engine, *Backend) {
r := gin.Default()
db, err := carrot.InitDatabase(nil, "", "")
if err != nil {
panic(err)
}
err = carrot.InitMigrate(db)
if err != nil {
log.Panic("init carrot migrate fail", err)
}
carrot.CheckValue(db, key_MAIL_DIR, "./mails/")
carrot.CheckValue(db, key_DOMAIN, "localhost")
carrot.CheckValue(db, key_AUTH_STRICT, "false")
carrot.CheckValue(db, key_MAIL_UUID_SIZE, "10")
be := &Backend{
db: db,
MailDir: carrot.GetValue(db, key_MAIL_DIR),
AuthStrict: carrot.GetBoolValue(db, key_AUTH_STRICT),
FilePerm: fileMode,
}
err = be.Prepare()
if err != nil {
log.Panic("Backend prepare fail", err)
}
RegisterHandlers(r.Group("/api"), be)
return r, be
}
func TestSummary(t *testing.T) {
router, _ := setupRouter()
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodPost, "/api/summary", nil)
router.ServeHTTP(w, req)
assert.Equal(t, http.StatusOK, w.Code)
}