package config import ( "encoding/json" "lab.evlic.cn/go/pkg/str" "sync" "testing" ) func TestUn(t *testing.T) { type Config struct { Type string `json:"type" mapstructure:"type" yaml:"type"` VXLanSvr string `json:"vxlan_svr" mapstructure:"vxlan_svr" yaml:"vxlan_svr"` Loop int64 `json:"loop" mapstructure:"loop" yaml:"loop"` Interval int `json:"interval" mapstructure:"interval" yaml:"interval"` DataPath []string `json:"data_path" mapstructure:"data_path" yaml:"data_path"` MaxTime int64 `json:"max_time" mapstructure:"max_time" yaml:"max_time"` } type Refer struct { sync.RWMutex Config `json:"runner" mapstructure:"runner" yaml:"runner"` } t.Run("write", func(t *testing.T) { r := new(Refer) r.DataPath = append(r.DataPath, "testing") t.Log(WriteConf("./testing/x.yaml", r)) }) t.Run("read", func(t *testing.T) { r := new(Refer) if err := ReadConf("../conf/runner.yaml", r); err != nil { t.Fatal(err) } res, err := json.Marshal(r) t.Log(str.B2S(res), err) }) }