pkg/config/config_test.go

40 lines
998 B
Go
Raw Normal View History

2023-09-18 15:51:20 +08:00
package pkg
import (
"encoding/json"
"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(B2S(res), err)
})
}