|
|
@ -10,6 +10,7 @@ import (
|
|
|
|
"bufio"
|
|
|
|
"bufio"
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"net/url"
|
|
|
|
"net/url"
|
|
|
@ -41,7 +42,6 @@ func (i Invoke) Command(name string, arg ...string) ([]byte, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type FakeInvoke struct {
|
|
|
|
type FakeInvoke struct {
|
|
|
|
CommandExpectedDir string // CommandExpectedDir specifies dir which includes expected outputs.
|
|
|
|
|
|
|
|
Suffix string // Suffix species expected file name suffix such as "fail"
|
|
|
|
Suffix string // Suffix species expected file name suffix such as "fail"
|
|
|
|
Error error // If Error specfied, return the error.
|
|
|
|
Error error // If Error specfied, return the error.
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -54,22 +54,18 @@ func (i FakeInvoke) Command(name string, arg ...string) ([]byte, error) {
|
|
|
|
|
|
|
|
|
|
|
|
arch := runtime.GOOS
|
|
|
|
arch := runtime.GOOS
|
|
|
|
|
|
|
|
|
|
|
|
fname := strings.Join(append([]string{name}, arg...), "")
|
|
|
|
commandName := filepath.Base(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fname := strings.Join(append([]string{commandName}, arg...), "")
|
|
|
|
fname = url.QueryEscape(fname)
|
|
|
|
fname = url.QueryEscape(fname)
|
|
|
|
var dir string
|
|
|
|
fpath := path.Join("testdata", arch, fname)
|
|
|
|
if i.CommandExpectedDir == "" {
|
|
|
|
|
|
|
|
dir = "expected"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dir = i.CommandExpectedDir
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fpath := path.Join(dir, arch, fname)
|
|
|
|
|
|
|
|
if i.Suffix != "" {
|
|
|
|
if i.Suffix != "" {
|
|
|
|
fpath += "_" + i.Suffix
|
|
|
|
fpath += "_" + i.Suffix
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if PathExists(fpath) {
|
|
|
|
if PathExists(fpath) {
|
|
|
|
return ioutil.ReadFile(fpath)
|
|
|
|
return ioutil.ReadFile(fpath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exec.Command(name, arg...).Output()
|
|
|
|
return []byte{}, fmt.Errorf("could not find testdata: %s", fpath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ErrNotImplementedError = errors.New("not implemented yet")
|
|
|
|
var ErrNotImplementedError = errors.New("not implemented yet")
|
|
|
|