| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- package conf
- import (
- "fmt"
- "git.shuncheng.lu/bigthing/gocommon/pkg/internal/properties"
- "testing"
- "time"
- )
- func mockConfig(t *testing.T, config string) {
- pro, err := properties.ReadFromString(config)
- if err != nil {
- t.Fatal(err)
- }
- MustValue = func(section, key string, defaultVal ...string) string {
- return pro.GetString(section+"."+key, defaultVal...)
- }
- }
- func Test_initNacosConfig(t *testing.T) {
- mockConfig(t, `
- nacos-config.data_id = go-template
- nacos-config.group = DEFAULT_GROUP
- nacos-config.host = 10.100.101.20:8848,10.100.99.14:8848
- nacos-config.log_path = /data/log/go-template
- nacos-config.namespace_id = 1bc32d85-1884-49b2-979d-8ced1f90ef35
- nacos-config.user_name = cityservice_dev_nacos
- nacos-config.password = MrHu0qvmdK
- nacos-config.log_level = error
- nacos-config.timeout = 5000
- `)
- if err := initNacosConfig(); err != nil {
- t.Fatal(err)
- }
- ticker := time.NewTicker(time.Second)
- for {
- <-ticker.C
- fmt.Println("k1: ", loadNacosConfig().GetString("k1"))
- }
- }
|