From 44c4e8f6e676b61dc06bc2f91d18c3f94bff5a54 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 1 Apr 2016 09:53:10 +0800 Subject: [PATCH 1/3] 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() From 34687c5e005bfebe38e7ff203ded678276273be4 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 1 Apr 2016 09:56:12 +0800 Subject: [PATCH 2/3] add travis. Signed-off-by: Bo-Yi Wu --- .travis.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a8236d0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +sudo: false + +language: go + +go: + - 1.3 + - 1.4 + - 1.5 + - 1.6 + - tip + +env: + global: + secure: ad5iOvyzCMdxp664YZD92Qse8EAB8R8jgoV8CspLBVbwfqPv2S+2IF2pHrxqd6o81y2sTgAr0VFOx9q9gVD3JZpT0vjpPIzscGNVYtup8bDBDFYIf3vwt6RVvJsSTYGQIQ6HulZ97CKB5W2pCI2q9pOrZqFzQG9lHA4J4m+XzAzH7eNx4PprboEwKKhESI4191ii47phWKcalcul00wo/oeM1u/Bmmg/rcGyQgzUHg3zFh+1avQp7z4yAMFmScRnJDJFABg9s9TVeQu8FQXUWTBv4tUQJrpPs60zRSxpt3ap9Yx67pkuVYpfZz9o9u6FLa8UC+zWVh+oHYXfYWrSmCcsyfLjy5Wg2Zt3Mx92Aqq8uiaGaLSxcn5pL9xeIK6X0uWixp2wzXMdjE9RkGRaPhTm/Ze4F810JyNR+i0AkM8py/gPEkVXkeIw+UGS/mo5bq4a5ntLKRbl1vePOIPUtpV8nlgBblNB6jqd3/wINRcCoNhNiKtr+uvUm1jKKK+hu4q9YncwG3gpB+u0DRR2KIPSgdUlzL3V43UMWIC12eEjVrS+xkMo7a2gfUXMzwmpMhQHZ2QMb0VMOgIde1X4nlOL0GHsrHJAp8AmjQF6xbv2gcxzs98zU9qKp/qm4QETGQvHaMXhvE8ogzx1EgXaJ0xn9SIAw11TBT6dpHLdcGI= + +install: + - go get -t -v ./... + - go get golang.org/x/tools/cmd/cover + - go get github.com/mattn/goveralls + +script: + - go test -v -covermode=count -coverprofile=coverage.out + - $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls -coverprofile=coverage.out + -service=travis-ci -repotoken=$COVERALLS_TOKEN From ed0999bced00dc5c83046899eba5af03c31637ca Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 1 Apr 2016 09:57:16 +0800 Subject: [PATCH 3/3] fix format. Signed-off-by: Bo-Yi Wu --- gorush/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gorush/config.go b/gorush/config.go index f56117c..9ea2fee 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"` - Mode string `yaml:"mode"` + Mode string `yaml:"mode"` SSL bool `yaml:"ssl"` CertPath string `yaml:"cert_path"` KeyPath string `yaml:"key_path"`