diff --git a/gorush/server_test.go b/gorush/server_test.go index 00670ea..596cd92 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -6,8 +6,11 @@ import ( "github.com/stretchr/testify/assert" "net/http" "testing" + "runtime" ) +var go_version = runtime.Version() + func initTest() { PushConf = BuildDefaultPushConf() PushConf.Core.Mode = "test" @@ -28,3 +31,35 @@ func TestRootHandler(t *testing.T) { assert.Equal(t, http.StatusOK, r.Code) }) } + +func TestAPIStatusHandler(t *testing.T) { + initTest() + + r := gofight.New() + + r.GET("/api/status"). + Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) { + data := []byte(r.Body.String()) + + value, _ := jsonparser.GetString(data, "go_version") + + assert.Equal(t, go_version, value) + assert.Equal(t, http.StatusOK, r.Code) + }) +} + +func TestPushHandler(t *testing.T) { + initTest() + + r := gofight.New() + + // missing some parameter. + r.POST("/api/push"). + SetJSON(gofight.D{ + "platform": 1, + }). + Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) { + + assert.Equal(t, http.StatusBadRequest, r.Code) + }) +}