mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
detail:
1. add utils.BytesToString function instead of string() convert bytes to string.
2. use bytes.NewReader instead of strings.NewReader(string(sb)).
3. use w.Body.Bytes() instead of []byte(w.Body.String()).
30 lines
609 B
Go
30 lines
609 B
Go
package mock
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetHomeStats(t *testing.T) {
|
|
var resp Response
|
|
w := httptest.NewRecorder()
|
|
req, _ := http.NewRequest("GET", "/stats/home", nil)
|
|
app.ServeHTTP(w, req)
|
|
err := json.Unmarshal(w.Body.Bytes(), &resp)
|
|
fmt.Println(resp.Data)
|
|
if err != nil {
|
|
t.Fatal("Unmarshal resp failed")
|
|
}
|
|
|
|
Convey("Test API GetHomeStats", t, func() {
|
|
Convey("Test response status", func() {
|
|
So(resp.Status, ShouldEqual, "ok")
|
|
So(resp.Message, ShouldEqual, "success")
|
|
})
|
|
})
|
|
}
|