func TestAPIBansakuGetHandler(t *testing.T) {
	router := echo.New()
	router.Static("/css", "static/css/api")
	tmp := p.PrepareTemplates(p.Options{
		Directory:  "../templates/",
		Extensions: []string{".tpl"},
	})
	router.SetRenderer(tmp)

	router.Get("/api/count", APIBansakuGetHandler)
	ts := httptest.NewServer(router)
	defer ts.Close()

	res, err := http.Get(ts.URL + "/api/count")
	if err != nil {
		t.Error("URL is not foung.")
	}
	if res.StatusCode != http.StatusOK {
		t.Error("Status code was wrong.")
	}
	defer res.Body.Close()
	b, err := ioutil.ReadAll(res.Body)
	if err != nil {
		t.Error("Can not parse body.")
	}
	js, err := simplejson.NewJson(b)
	if err != nil {
		t.Error("Can not get json.")
	}
	_, err = js.Get("count").Int64()
	if err != nil {
		t.Error("Can not get count.")
	}
}
Example #2
0
// NewRoutes return routes
func NewRoutes() *echo.Echo {
	bansaku := echo.New()
	bansaku.Static("/js", "static/js")
	bansaku.Static("/css", "static/css/bansaku")
	bansaku.Static("/sound", "static/sound")
	bansaku.Static("/font", "static/font")
	bansaku.Use(mw.Logger())
	bansaku.Use(mw.Recover())
	t := p.PrepareTemplates(p.Options{
		Directory:  "templates/",
		Extensions: []string{".tpl"},
	})
	bansaku.SetRenderer(t)

	// Debug
	bansaku.SetDebug(true)
	server := controllers.NewBansakuServer()
	go server.Start()
	bansaku.Get("/", controllers.BansakuIndex)
	bansaku.WebSocket("/ws", server.BansakuSocketHandler())

	// API
	api := bansaku.Group("/api")
	api.Static("/css", "static/css/api")
	api.Get("/", controllers.APIReferenceHandler)
	api.Get("/count", controllers.APIBansakuGetHandler)

	return bansaku
}
func TestBansakuIndex(t *testing.T) {
	router := echo.New()
	router.Static("/js", "static/js")
	router.Static("/css", "static/css/bansaku")
	router.Static("/sound", "static/sound")
	router.Static("/font", "static/font")
	tmp := p.PrepareTemplates(p.Options{
		Directory:  "../templates/",
		Extensions: []string{".tpl"},
	})
	router.SetRenderer(tmp)
	server := NewBansakuServer()
	go server.Start()
	router.Get("/", BansakuIndex)
	router.WebSocket("/ws", server.BansakuSocketHandler())

	ts := httptest.NewServer(router)
	defer ts.Close()

	res, err := http.Get(ts.URL)
	if err != nil {
		t.Error("URL is not found.")
	}
	if res.StatusCode != http.StatusOK {
		t.Error("Status code is wrong.")
	}
}
func TestAPIReferenceHandler(t *testing.T) {
	router := echo.New()
	router.Static("/css", "static/css/api")
	tmp := p.PrepareTemplates(p.Options{
		Directory:  "../templates/",
		Extensions: []string{".tpl"},
	})
	router.SetRenderer(tmp)

	router.Get("/api/", APIReferenceHandler)

	ts := httptest.NewServer(router)
	defer ts.Close()

	res, err := http.Get(ts.URL + "/api/")
	if err != nil {
		t.Error("URL is not found.")
	}
	if res.StatusCode != http.StatusOK {
		t.Error("Status code is wrong.")
	}

}