tracker/server/stats_test.go

49 lines
992 B
Go
Raw Normal View History

// 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"
"testing"
2013-12-01 04:39:02 +01:00
"github.com/chihaya/chihaya/config"
2013-12-02 11:00:28 +01:00
_ "github.com/chihaya/chihaya/storage/backend/mock"
2013-12-01 05:08:31 +01:00
_ "github.com/chihaya/chihaya/storage/tracker/mock"
)
2013-08-29 06:47:37 +02:00
func newTestServer() (*Server, error) {
2013-12-02 11:00:28 +01:00
s, err := New(&config.MockConfig)
2013-11-24 06:49:20 +01:00
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"))
}
}