wheat-cache/conf/public_conf_test.go

44 lines
948 B
Go
Raw Normal View History

2021-09-05 17:08:13 +08:00
package conf
import (
2021-10-09 21:56:43 +08:00
"fmt"
2021-09-05 17:08:13 +08:00
"testing"
"github.com/spf13/viper"
"github.com/stretchr/testify/require"
)
2021-09-27 11:29:47 +08:00
func TestConf(t *testing.T) {
2021-10-09 21:56:43 +08:00
2021-09-27 11:29:47 +08:00
// 外部导入 conf.yaml 需要导入 conf 包
// 每次迁移文件时, 使用 sudo make init-conf来将yam文件迁移到指定的文件夹下
2021-09-27 11:29:47 +08:00
// get 使用, 读取 public_conf 配置文件
h := viper.Get("storage.host")
require.Equal(t, h, "127.0.0.1")
2021-09-05 17:08:13 +08:00
2021-09-27 11:29:47 +08:00
h = viper.Get("env")
require.Equal(t, h, "dev")
// set 使用
2021-09-05 17:08:13 +08:00
viper.Set("host", "1222")
host := viper.GetString("host")
require.Equal(t, host, "1222")
}
2021-10-09 21:56:43 +08:00
func TestMiddleConf(t *testing.T) {
ct := viper.GetStringMap("plugins-control")
fmt.Println(ct)
d := viper.GetInt("middleware-driver.driverCount")
require.Equal(t, d, 1000)
c := viper.GetInt("middleware-driver.middleConsumerCount")
require.Equal(t, c, 5)
p := viper.GetStringMap("plugins-control")
for key, val := range p {
fmt.Println(key, val)
}
// fmt.Println(p)
}