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 (
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/pushrax/chihaya/config"
|
|
|
|
|
|
|
|
_ "github.com/pushrax/chihaya/cache/redis"
|
2013-09-07 01:13:44 +02:00
|
|
|
_ "github.com/pushrax/chihaya/storage/batter"
|
2013-08-29 05:44:45 +02:00
|
|
|
)
|
|
|
|
|
2013-08-29 06:47:37 +02:00
|
|
|
func newTestServer() (*Server, error) {
|
|
|
|
testConfig, err := config.Open(os.Getenv("TESTCONFIGPATH"))
|
2013-08-29 05:44:45 +02:00
|
|
|
if err != nil {
|
2013-08-29 06:24:31 +02:00
|
|
|
return nil, err
|
2013-08-29 05:44:45 +02:00
|
|
|
}
|
2013-08-29 06:24:31 +02:00
|
|
|
|
2013-08-29 05:44:45 +02:00
|
|
|
s, err := New(testConfig)
|
2013-08-29 06:24:31 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return s, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStats(t *testing.T) {
|
2013-08-29 06:47:37 +02:00
|
|
|
s, err := newTestServer()
|
2013-08-29 05:44:45 +02:00
|
|
|
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"))
|
|
|
|
}
|
|
|
|
}
|