forked from gernest/utron
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutron_test.go
More file actions
42 lines (34 loc) · 796 Bytes
/
utron_test.go
File metadata and controls
42 lines (34 loc) · 796 Bytes
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
package utron
import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gernest/utron/controller"
)
type SimpleMVC struct {
*controller.BaseController
}
func (s *SimpleMVC) Hello() {
s.Ctx.Data["Name"] = "gernest"
s.Ctx.Template = "index"
s.String(http.StatusOK)
}
func TestMVC(t *testing.T) {
app, err := NewMVC("fixtures/mvc")
if err != nil {
fmt.Println(err)
t.Skip(err)
}
app.AddController(controller.GetCtrlFunc(&SimpleMVC{}))
req, _ := http.NewRequest("GET", "/simplemvc/hello", nil)
w := httptest.NewRecorder()
app.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Errorf("expcted %d got %d", http.StatusOK, w.Code)
}
if !strings.Contains(w.Body.String(), "gernest") {
t.Errorf("expected %s to contain gernest", w.Body.String())
}
}