mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-08 17:48:12 -07:00
stats test, add/remove torrent handlers, init batter driver
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// 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 (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (s Server) serveAdd(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s Server) serveRemove(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
+8
-1
@@ -96,9 +96,16 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
defer s.waitgroup.Done()
|
||||
defer atomic.AddInt64(&s.deltaRequests, 1)
|
||||
|
||||
if r.URL.Path == "/stats" {
|
||||
switch r.URL.Path {
|
||||
case "/stats":
|
||||
s.serveStats(w, r)
|
||||
return
|
||||
case "/add":
|
||||
s.serveAdd(w, r)
|
||||
return
|
||||
case "/remove":
|
||||
s.serveRemove(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
_, action := path.Split(r.URL.Path)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/pushrax/chihaya/config"
|
||||
|
||||
_ "github.com/pushrax/chihaya/cache/redis"
|
||||
_ "github.com/pushrax/chihaya/storage/batter"
|
||||
)
|
||||
|
||||
func TestStats(t *testing.T) {
|
||||
testConfig, err := config.Open(os.ExpandEnv("$GOPATH/src/github.com/pushrax/chihaya/config/example.json"))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fmt.Println(testConfig)
|
||||
s, err := New(testConfig)
|
||||
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"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user