testutils: pass netConf in for version operations; pass raw result out for tests
This commit is contained in:
parent
2515b8c712
commit
dae1177b53
@ -29,7 +29,7 @@ func envCleanup() {
|
|||||||
os.Unsetenv("CNI_IFNAME")
|
os.Unsetenv("CNI_IFNAME")
|
||||||
}
|
}
|
||||||
|
|
||||||
func CmdAddWithResult(cniNetns, cniIfname string, f func() error) (*types.Result, error) {
|
func CmdAddWithResult(cniNetns, cniIfname string, conf []byte, f func() error) (*types.Result, []byte, error) {
|
||||||
os.Setenv("CNI_COMMAND", "ADD")
|
os.Setenv("CNI_COMMAND", "ADD")
|
||||||
os.Setenv("CNI_PATH", os.Getenv("PATH"))
|
os.Setenv("CNI_PATH", os.Getenv("PATH"))
|
||||||
os.Setenv("CNI_NETNS", cniNetns)
|
os.Setenv("CNI_NETNS", cniNetns)
|
||||||
@ -40,30 +40,30 @@ func CmdAddWithResult(cniNetns, cniIfname string, f func() error) (*types.Result
|
|||||||
oldStdout := os.Stdout
|
oldStdout := os.Stdout
|
||||||
r, w, err := os.Pipe()
|
r, w, err := os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Stdout = w
|
os.Stdout = w
|
||||||
err = f()
|
err = f()
|
||||||
w.Close()
|
w.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the result
|
// parse the result
|
||||||
out, err := ioutil.ReadAll(r)
|
out, err := ioutil.ReadAll(r)
|
||||||
os.Stdout = oldStdout
|
os.Stdout = oldStdout
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
result := types.Result{}
|
result := types.Result{}
|
||||||
err = json.Unmarshal(out, &result)
|
err = json.Unmarshal(out, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &result, nil
|
return &result, out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CmdDelWithResult(cniNetns, cniIfname string, f func() error) error {
|
func CmdDelWithResult(cniNetns, cniIfname string, f func() error) error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user