From 44c4e8f6e676b61dc06bc2f91d18c3f94bff5a54 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 1 Apr 2016 09:53:10 +0800 Subject: [PATCH] Add unit testing. Signed-off-by: Bo-Yi Wu --- config/apns.yaml | 2 +- gorush/config.go | 4 ++-- gorush/server.go | 5 ++--- gorush/server_test.go | 5 ++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/config/apns.yaml b/config/apns.yaml index 7223614..8426ebd 100644 --- a/config/apns.yaml +++ b/config/apns.yaml @@ -1,7 +1,7 @@ core: port: "8088" notification_max: 100 - production: true + mode: "release" ssl: false cert_path: "cert.pem" key_path: "key.pem" diff --git a/gorush/config.go b/gorush/config.go index ead7f44..f56117c 100644 --- a/gorush/config.go +++ b/gorush/config.go @@ -16,7 +16,7 @@ type ConfYaml struct { type SectionCore struct { Port string `yaml:"port"` NotificationMax int `yaml:"notification_max"` - Production bool `yaml:"production"` + Mode string `yaml:"mode"` SSL bool `yaml:"ssl"` CertPath string `yaml:"cert_path"` KeyPath string `yaml:"key_path"` @@ -45,7 +45,7 @@ func BuildDefaultPushConf() ConfYaml { // Core conf.Core.Port = "8088" conf.Core.NotificationMax = 100 - conf.Core.Production = true + conf.Core.Mode = "release" conf.Core.SSL = false conf.Core.CertPath = "cert.pem" conf.Core.KeyPath = "key.pem" diff --git a/gorush/server.go b/gorush/server.go index 079ab33..5fc9e0e 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -39,9 +39,8 @@ func pushHandler(c *gin.Context) { } func GetMainEngine() *gin.Engine { - if PushConf.Core.Production { - gin.SetMode(gin.ReleaseMode) - } + // set server mode + gin.SetMode(PushConf.Core.Mode) r := gin.New() diff --git a/gorush/server_test.go b/gorush/server_test.go index 6842a0d..00670ea 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -3,18 +3,17 @@ 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() + PushConf.Core.Mode = "test" } -func TestGinHelloWorld(t *testing.T) { +func TestRootHandler(t *testing.T) { initTest() r := gofight.New()