From 833befcf1cf398fa94b903a664c83d1fbed1355b Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 1 Apr 2016 00:35:53 +0800 Subject: [PATCH] initial api test. Signed-off-by: Bo-Yi Wu --- gorush/server_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 gorush/server_test.go diff --git a/gorush/server_test.go b/gorush/server_test.go new file mode 100644 index 0000000..6842a0d --- /dev/null +++ b/gorush/server_test.go @@ -0,0 +1,31 @@ +package gopush + +import ( + "github.com/appleboy/gofight" + "github.com/buger/jsonparser" + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/assert" + "net/http" + "testing" +) + +func initTest() { + gin.SetMode(gin.TestMode) + PushConf = BuildDefaultPushConf() +} + +func TestGinHelloWorld(t *testing.T) { + initTest() + + r := gofight.New() + + r.GET("/"). + Run(GetMainEngine(), func(r gofight.HttpResponse, rq gofight.HttpRequest) { + data := []byte(r.Body.String()) + + value, _ := jsonparser.GetString(data, "text") + + assert.Equal(t, "Welcome to notification server.", value) + assert.Equal(t, http.StatusOK, r.Code) + }) +}