1
0
镜像自地址 https://github.com/tuna/tunasync.git 已同步 2025-12-06 14:36:47 +00:00

feature(manager): skeleton of status API

这个提交包含在:
bigeagle
2016-04-10 22:28:34 +08:00
父节点 350767e501
当前提交 ed896b16c1
共有 3 个文件被更改,包括 75 次插入0 次删除

37
manager/server_test.go 普通文件
查看文件

@@ -0,0 +1,37 @@
package manager
import (
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestHTTPServer(t *testing.T) {
Convey("HTTP server should work", t, func() {
s := makeHTTPServer(false)
So(s, ShouldNotBeNil)
port := rand.Intn(10000) + 20000
go func() {
s.Run(fmt.Sprintf("127.0.0.1:%d", port))
}()
time.Sleep(50 * time.Microsecond)
resp, err := http.Get(fmt.Sprintf("http://127.0.0.1:%d/ping", port))
So(err, ShouldBeNil)
So(resp.StatusCode, ShouldEqual, http.StatusOK)
So(resp.Header.Get("Content-Type"), ShouldEqual, "application/json; charset=utf-8")
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
So(err, ShouldBeNil)
var p map[string]string
err = json.Unmarshal(body, &p)
So(err, ShouldBeNil)
So(p["msg"], ShouldEqual, "pong")
})
}