Add unit testing.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-04-01 09:53:10 +08:00
parent 833befcf1c
commit 44c4e8f6e6
4 changed files with 7 additions and 9 deletions

View File

@ -1,7 +1,7 @@
core: core:
port: "8088" port: "8088"
notification_max: 100 notification_max: 100
production: true mode: "release"
ssl: false ssl: false
cert_path: "cert.pem" cert_path: "cert.pem"
key_path: "key.pem" key_path: "key.pem"

View File

@ -16,7 +16,7 @@ type ConfYaml struct {
type SectionCore struct { type SectionCore struct {
Port string `yaml:"port"` Port string `yaml:"port"`
NotificationMax int `yaml:"notification_max"` NotificationMax int `yaml:"notification_max"`
Production bool `yaml:"production"` Mode string `yaml:"mode"`
SSL bool `yaml:"ssl"` SSL bool `yaml:"ssl"`
CertPath string `yaml:"cert_path"` CertPath string `yaml:"cert_path"`
KeyPath string `yaml:"key_path"` KeyPath string `yaml:"key_path"`
@ -45,7 +45,7 @@ func BuildDefaultPushConf() ConfYaml {
// Core // Core
conf.Core.Port = "8088" conf.Core.Port = "8088"
conf.Core.NotificationMax = 100 conf.Core.NotificationMax = 100
conf.Core.Production = true conf.Core.Mode = "release"
conf.Core.SSL = false conf.Core.SSL = false
conf.Core.CertPath = "cert.pem" conf.Core.CertPath = "cert.pem"
conf.Core.KeyPath = "key.pem" conf.Core.KeyPath = "key.pem"

View File

@ -39,9 +39,8 @@ func pushHandler(c *gin.Context) {
} }
func GetMainEngine() *gin.Engine { func GetMainEngine() *gin.Engine {
if PushConf.Core.Production { // set server mode
gin.SetMode(gin.ReleaseMode) gin.SetMode(PushConf.Core.Mode)
}
r := gin.New() r := gin.New()

View File

@ -3,18 +3,17 @@ package gopush
import ( import (
"github.com/appleboy/gofight" "github.com/appleboy/gofight"
"github.com/buger/jsonparser" "github.com/buger/jsonparser"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"net/http" "net/http"
"testing" "testing"
) )
func initTest() { func initTest() {
gin.SetMode(gin.TestMode)
PushConf = BuildDefaultPushConf() PushConf = BuildDefaultPushConf()
PushConf.Core.Mode = "test"
} }
func TestGinHelloWorld(t *testing.T) { func TestRootHandler(t *testing.T) {
initTest() initTest()
r := gofight.New() r := gofight.New()