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:
port: "8088"
notification_max: 100
production: true
mode: "release"
ssl: false
cert_path: "cert.pem"
key_path: "key.pem"

View File

@ -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"

View File

@ -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()

View File

@ -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()