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
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2013-08-29 05:44:45 +02:00
|
|
|
|
2013-12-01 04:39:02 +01:00
|
|
|
"github.com/chihaya/chihaya/config"
|
2013-08-29 05:44:45 +02:00
|
|
|
|
2013-12-01 04:39:02 +01:00
|
|
|
_ "github.com/chihaya/chihaya/storage/backend/batter"
|
|
|
|
_ "github.com/chihaya/chihaya/storage/tracker/redis"
|
2013-08-29 05:44:45 +02:00
|
|
|
)
|
|
|
|
|
2013-08-29 06:47:37 +02:00
|
|
|
func newTestServer() (*Server, error) {
|
2013-11-24 06:49:20 +01:00
|
|
|
testConfig, err := config.Open(os.Getenv("TESTCONFIGPATH"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-08-29 06:24:31 +02:00
|
|
|
|
2013-11-24 06:49:20 +01:00
|
|
|
s, err := New(testConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-08-29 06:24:31 +02:00
|
|
|
|
2013-11-24 06:49:20 +01:00
|
|
|
return s, nil
|
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 {
|
|
|
|
t.Error(errors.New("/stats did not return HTTP 200"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if w.Header()["Content-Type"][0] != "application/json" {
|
|
|
|
t.Error(errors.New("/stats did not return the proper Content-Type header"))
|
|
|
|
}
|
2013-08-29 05:44:45 +02:00
|
|
|
}
|