43 lines
774 B
Go
43 lines
774 B
Go
![]() |
package config
|
||
|
|
||
|
import (
|
||
|
"github.com/fox/fox/db"
|
||
|
"github.com/fox/fox/log"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
redisHost = "114.132.124.145"
|
||
|
redisPort = "6379"
|
||
|
redisPassword = "fox379@@zyxi"
|
||
|
specialKey = "test_config"
|
||
|
)
|
||
|
|
||
|
func initLog() {
|
||
|
log.Open("test.log", log.DebugL)
|
||
|
}
|
||
|
|
||
|
type specialConfig struct {
|
||
|
Rate int `json:"rate"`
|
||
|
}
|
||
|
|
||
|
func TestConfig(t *testing.T) {
|
||
|
initLog()
|
||
|
rdb, err := db.InitRedis(redisPassword, redisHost, redisPort, 0)
|
||
|
if err != nil {
|
||
|
log.Error(err.Error())
|
||
|
return
|
||
|
}
|
||
|
comm, err := LoadCommonConfig[specialConfig](rdb)
|
||
|
if err != nil {
|
||
|
log.Error(err.Error())
|
||
|
return
|
||
|
}
|
||
|
if err = LoadSpecialConfig[specialConfig](rdb, specialKey, comm); err != nil {
|
||
|
log.Error(err.Error())
|
||
|
} else {
|
||
|
log.DebugF("load common config success:%#v", comm)
|
||
|
}
|
||
|
|
||
|
}
|