func Test_GetEyeConfig(t *testing.T) { eye := &Eye{ Servers: []string{"localhost:7900 0 1 2", "127.0.0.1:7900 A -1 B"}, Port: 7905, WebPort: 7908, Threads: 8, N: 3, W: 2, R: 1, Buckets: 16, Listen: "0.0.0.0", Slow: 200, Proxies: []string{"localhost:7905"}, AccessLog: "/log/beansproxy/beansproxy.log", ErrorLog: "/log/beansproxy/beansproxy_error.log", Basepath: "/var/lib/beanseye", Readonly: false, } content1, _ := goyaml.Marshal(eye) ioutil.WriteFile("./example.yaml", content1, os.ModePerm) var new_eye Eye content, _ := ioutil.ReadFile("./example.yaml") goyaml.Unmarshal(content, &new_eye) fmt.Println("eye") fmt.Println(*eye) fmt.Println("new_eye") fmt.Println(new_eye) }
func Test_GetFarmConfig(t *testing.T) { var f FarmConfig f.Db = "highway" f.Addr = "127.0.0.1" f.Port = uint16(3000) f.Hosts = make([]HostConfig, 4) f.Hosts[0].Name = "master" f.Hosts[0].Addr = "127.0.0.1:3306" f.Hosts[0].Master = true f.Hosts[0].Weight = 0 f.Hosts[0].ConnMax = 400 f.Hosts[0].UserPools = []UserPoolConfig{ {User: "******", Passwd: "code", Max: 100, Min: 50}, {User: "******", Passwd: "password", Max: 100, Min: 50}, {User: "******", Passwd: "password", Max: 100, Min: 50}, } f.Hosts[1].Name = "slave" f.Hosts[1].Addr = "127.0.0.1:3306" f.Hosts[1].Master = false f.Hosts[1].Weight = 50 f.Hosts[1].ConnMax = 400 f.Hosts[1].UserPools = []UserPoolConfig{ {User: "******", Passwd: "code", Max: 100, Min: 50}, {User: "******", Passwd: "password", Max: 100, Min: 50}, {User: "******", Passwd: "password", Max: 100, Min: 50}, } f.Hosts[2].Name = "backup" f.Hosts[2].Addr = "localhost:3306" f.Hosts[2].Master = false f.Hosts[2].Weight = 30 f.Hosts[2].ConnMax = 400 f.Hosts[2].UserPools = []UserPoolConfig{ {User: "******", Passwd: "code", Max: 100, Min: 50}, {User: "******", Passwd: "password", Max: 100, Min: 50}, {User: "******", Passwd: "password", Max: 100, Min: 50}, } f.Hosts[3].Name = "query" f.Hosts[3].Addr = "localhost:3306" f.Hosts[3].Master = false f.Hosts[3].Weight = 20 f.Hosts[3].ConnMax = 400 f.Hosts[3].UserPools = []UserPoolConfig{ {User: "******", Passwd: "code", Max: 100, Min: 50}, {User: "******", Passwd: "password", Max: 100, Min: 50}, {User: "******", Passwd: "password", Max: 100, Min: 50}, } out, e := goyaml.Marshal(f) if e != nil { t.Errorf("goyaml marshal failed") } var new_f FarmConfig goyaml.Unmarshal(out, &new_f) if !test_comp_farm_config(&f, &new_f) { t.Errorf("f not same to new_f") } }