nacos_test.go 997 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package conf
  2. import (
  3. "fmt"
  4. "git.shuncheng.lu/bigthing/gocommon/pkg/internal/properties"
  5. "testing"
  6. "time"
  7. )
  8. func mockConfig(t *testing.T, config string) {
  9. pro, err := properties.ReadFromString(config)
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. MustValue = func(section, key string, defaultVal ...string) string {
  14. return pro.GetString(section+"."+key, defaultVal...)
  15. }
  16. }
  17. func Test_initNacosConfig(t *testing.T) {
  18. mockConfig(t, `
  19. nacos-config.data_id = go-template
  20. nacos-config.group = DEFAULT_GROUP
  21. nacos-config.host = 10.100.101.20:8848,10.100.99.14:8848
  22. nacos-config.log_path = /data/log/go-template
  23. nacos-config.namespace_id = 1bc32d85-1884-49b2-979d-8ced1f90ef35
  24. nacos-config.user_name = cityservice_dev_nacos
  25. nacos-config.password = MrHu0qvmdK
  26. nacos-config.log_level = error
  27. nacos-config.timeout = 5000
  28. `)
  29. if err := initNacosConfig(); err != nil {
  30. t.Fatal(err)
  31. }
  32. ticker := time.NewTicker(time.Second)
  33. for {
  34. <-ticker.C
  35. fmt.Println("k1: ", loadNacosConfig().GetString("k1"))
  36. }
  37. }