2013-08-29 05:44:45 +02:00
|
|
|
// Copyright 2013 The Chihaya Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by the BSD 2-Clause license,
|
|
|
|
// which can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2013-11-24 06:49:20 +01:00
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
2013-08-29 05:44:45 +02:00
|
|
|
|
2013-12-01 04:39:02 +01:00
|
|
|
"github.com/chihaya/chihaya/config"
|
2014-06-24 04:47:43 +02:00
|
|
|
_ "github.com/chihaya/chihaya/drivers/backend/mock"
|
|
|
|
_ "github.com/chihaya/chihaya/drivers/tracker/mock"
|
2013-08-29 05:44:45 +02:00
|
|
|
)
|
|
|
|
|
2013-08-29 06:47:37 +02:00
|
|
|
func newTestServer() (*Server, error) {
|
2013-12-13 17:48:47 +01:00
|
|
|
return New(&config.MockConfig)
|
2013-08-29 06:24:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStats(t *testing.T) {
|
2013-11-24 06:49:20 +01:00
|
|
|
s, err := newTestServer()
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := http.NewRequest("GET", "127.0.0.1:80/stats", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
s.serveStats(w, r)
|
|
|
|
|
|
|
|
if w.Code != 200 {
|
2013-12-13 17:48:47 +01:00
|
|
|
t.Error("/stats did not return 200 OK")
|
2013-11-24 06:49:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if w.Header()["Content-Type"][0] != "application/json" {
|
2013-12-13 17:48:47 +01:00
|
|
|
t.Error("/stats did not return JSON")
|
2013-11-24 06:49:20 +01:00
|
|
|
}
|
2013-08-29 05:44:45 +02:00
|
|
|
}
|