DupConf duplicate conf file using random new listen addr to avoid failure on concurrent test cases.
(confFile string, newConfFile string)
| 24 | |
| 25 | // DupConf duplicate conf file using random new listen addr to avoid failure on concurrent test cases. |
| 26 | func DupConf(confFile string, newConfFile string) (err error) { |
| 27 | // replace port in confFile |
| 28 | var fileBytes []byte |
| 29 | if fileBytes, err = ioutil.ReadFile(confFile); err != nil { |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | var ports []int |
| 34 | if ports, err = GetRandomPorts("127.0.0.1", 4000, 6000, 1); err != nil { |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | newConfBytes := bytes.Replace(fileBytes, []byte(":2230"), []byte(fmt.Sprintf(":%v", ports[0])), -1) |
| 39 | |
| 40 | return ioutil.WriteFile(newConfFile, newConfBytes, 0644) |
| 41 | } |