rename expected dir to testdata.

pull/332/head
WAKAYAMA Shirou 8 years ago
parent f8ef680a47
commit 30ebb9ca3a

@ -23,7 +23,7 @@ func TestParseDmesgBoot(t *testing.T) {
{"2cpu_4core.txt", 2, 4}, {"2cpu_4core.txt", 2, 4},
} }
for _, tt := range cpuTests { for _, tt := range cpuTests {
v, num, err := parseDmesgBoot(filepath.Join("expected/freebsd/", tt.file)) v, num, err := parseDmesgBoot(filepath.Join("testdatak", "freebsd", tt.file))
if err != nil { if err != nil {
t.Errorf("parseDmesgBoot failed(%s), %v", tt.file, err) t.Errorf("parseDmesgBoot failed(%s), %v", tt.file, err)
} }

@ -36,7 +36,7 @@ func TestParseISAInfo(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
content, err := ioutil.ReadFile(filepath.Join("expected", "solaris", tc.filename)) content, err := ioutil.ReadFile(filepath.Join("testdata", "solaris", tc.filename))
if err != nil { if err != nil {
t.Errorf("cannot read test case: %s", err) t.Errorf("cannot read test case: %s", err)
} }
@ -96,7 +96,7 @@ func TestParseProcessorInfo(t *testing.T) {
} }
for _, tc := range cases { for _, tc := range cases {
content, err := ioutil.ReadFile(filepath.Join("expected", "solaris", tc.filename)) content, err := ioutil.ReadFile(filepath.Join("testdata", "solaris", tc.filename))
if err != nil { if err != nil {
t.Errorf("cannot read test case: %s", err) t.Errorf("cannot read test case: %s", err)
} }

@ -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")

Loading…
Cancel
Save