Skip to content

Commit

Permalink
tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Nov 23, 2020
1 parent 4f788ba commit 498518b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/apis/apis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/axiaoxin-com/goutils"
"github.com/axiaoxin-com/pink-lady/services"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand All @@ -15,8 +16,11 @@ func TestRegisterRoutes(t *testing.T) {
// Register 中的 basic auth 依赖 viper 配置
viper.Set("basic_auth.username", "admin")
viper.Set("basic_auth.password", "admin")
viper.Set("env", "localhost")
defer viper.Reset()

services.Init()

Register(r)
recorder, err := goutils.RequestHTTPHandler(r, "GET", "/x/ping", nil, map[string]string{"Authorization": "Basic YWRtaW46YWRtaW4="})
assert.Nil(t, err)
Expand Down
14 changes: 8 additions & 6 deletions src/services/services_health.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ import (

// CheckMySQL 检查 mysql 服务状态
func CheckMySQL(ctx context.Context) map[string]string {
// 检查默认 mysql
defaultMySQLStatus := "ok"
if sqlDB, err := DB(ctx).DB(); err != nil {
defaultMySQLStatus = err.Error()
// 检查本地 mysql
localhostMySQLStatus := "ok"
if localhostMySQL, err := goutils.GormMySQL("localhost"); err != nil {
localhostMySQLStatus = err.Error()
} else if sqlDB, err := localhostMySQL.DB(); err != nil {
localhostMySQLStatus = err.Error()
} else if err := sqlDB.Ping(); err != nil {
defaultMySQLStatus = err.Error()
localhostMySQLStatus = err.Error()
}
return map[string]string{
"default DB": defaultMySQLStatus,
"localhost": localhostMySQLStatus,
}
}

Expand Down

0 comments on commit 498518b

Please sign in to comment.