invoke: backfill tests for plugin execution

This commit is contained in:
Gabe Rosenhouse
2016-08-30 23:52:47 -04:00
parent 9d5e6e60e7
commit d3ecadb860
5 changed files with 158 additions and 3 deletions

View File

@ -18,6 +18,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
@ -57,15 +58,25 @@ func ExecPluginWithoutResult(pluginPath string, netconf []byte, args CNIArgs) er
}
func execPlugin(pluginPath string, netconf []byte, args CNIArgs) ([]byte, error) {
return defaultRawExec.ExecPlugin(pluginPath, netconf, args.AsEnv())
}
var defaultRawExec = &RawExec{Stderr: os.Stderr}
type RawExec struct {
Stderr io.Writer
}
func (e *RawExec) ExecPlugin(pluginPath string, stdinData []byte, environ []string) ([]byte, error) {
stdout := &bytes.Buffer{}
c := exec.Cmd{
Env: args.AsEnv(),
Env: environ,
Path: pluginPath,
Args: []string{pluginPath},
Stdin: bytes.NewBuffer(netconf),
Stdin: bytes.NewBuffer(stdinData),
Stdout: stdout,
Stderr: os.Stderr,
Stderr: e.Stderr,
}
if err := c.Run(); err != nil {
return nil, pluginErr(err, stdout.Bytes())