Files
goProject/.svn/pristine/14/14de84ff1959026fcd250504d7000e59f58e3b41.svn-base
T

54 lines
1.4 KiB
Plaintext

package configUtil
import (
"testing"
)
var (
config map[string]interface{}
err error
)
func TestReadJsonConfig(t *testing.T) {
config, err = ReadJsonConfig("testdata/jsonConfig.ini")
if err != nil {
t.Errorf("读取JSON配置失败,错误信息为:%s", err)
}
}
func TestReadIntJsonValue(t *testing.T) {
actualValue, err := ReadIntJsonValue(config, "ServerGroupId")
if err != nil {
t.Errorf("读取JSON配置失败,错误信息为:%s", err)
}
expectedValue := 1
if actualValue != expectedValue {
t.Errorf("期望的值为%d,实际的值为%d", expectedValue, actualValue)
}
}
func TestReadStringJsonValue(t *testing.T) {
actualValue, err := ReadStringJsonValue(config, "ChatDBConnection")
if err != nil {
t.Errorf("读取JSON配置失败,错误信息为:%s", err)
}
expectedValue := "root:moqikaka@tcp(192.168.1.226:3306)/chatserver?charset=utf8&parseTime=true&loc=Local&timeout=30s"
if actualValue != expectedValue {
t.Errorf("期望的值为%s,实际的值为%s", expectedValue, actualValue)
}
}
func TestReadBoolJsonValue(t *testing.T) {
actualValue, err := ReadBoolJsonValue(config, "IfRecordMessage")
if err != nil {
t.Errorf("读取JSON配置失败,错误信息为:%s", err)
}
expectedValue := true
if actualValue != expectedValue {
t.Errorf("期望的值为%v,实际的值为%v", expectedValue, actualValue)
}
}