mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 11:42:43 +00:00
increse test coverage
This commit is contained in:
parent
b6043142e1
commit
2f6a61aee5
@ -21,9 +21,16 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestHTTPServer(t *testing.T) {
|
func TestHTTPServer(t *testing.T) {
|
||||||
|
var listenPort = 5000
|
||||||
Convey("HTTP server should work", t, func(ctx C) {
|
Convey("HTTP server should work", t, func(ctx C) {
|
||||||
|
listenPort++
|
||||||
|
port := listenPort
|
||||||
|
addr := "127.0.0.1"
|
||||||
|
baseURL := fmt.Sprintf("http://%s:%d", addr, port)
|
||||||
InitLogger(true, true, false)
|
InitLogger(true, true, false)
|
||||||
s := GetTUNASyncManager(&Config{Debug: false})
|
s := GetTUNASyncManager(&Config{Debug: true})
|
||||||
|
s.cfg.Server.Addr = addr
|
||||||
|
s.cfg.Server.Port = port
|
||||||
So(s, ShouldNotBeNil)
|
So(s, ShouldNotBeNil)
|
||||||
s.setDBAdapter(&mockDBAdapter{
|
s.setDBAdapter(&mockDBAdapter{
|
||||||
workerStore: map[string]WorkerStatus{
|
workerStore: map[string]WorkerStatus{
|
||||||
@ -32,12 +39,8 @@ func TestHTTPServer(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
statusStore: make(map[string]MirrorStatus),
|
statusStore: make(map[string]MirrorStatus),
|
||||||
})
|
})
|
||||||
port := rand.Intn(10000) + 20000
|
go s.Run()
|
||||||
baseURL := fmt.Sprintf("http://127.0.0.1:%d", port)
|
time.Sleep(50 * time.Millisecond)
|
||||||
go func() {
|
|
||||||
s.engine.Run(fmt.Sprintf("127.0.0.1:%d", port))
|
|
||||||
}()
|
|
||||||
time.Sleep(50 * time.Microsecond)
|
|
||||||
resp, err := http.Get(baseURL + "/ping")
|
resp, err := http.Get(baseURL + "/ping")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(resp.StatusCode, ShouldEqual, http.StatusOK)
|
So(resp.StatusCode, ShouldEqual, http.StatusOK)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user