-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjob_test.go
More file actions
60 lines (57 loc) · 1.17 KB
/
Copy pathjob_test.go
File metadata and controls
60 lines (57 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package fastexec
import (
"bytes"
"errors"
"os"
"testing"
)
func TestExecJobs(t *testing.T) {
testCases := []struct {
about string
job ExecJob
err error
expected []byte
}{
{
about: "simple cat",
job: ExecJob{
args: []string{"cat"},
data: []byte("A\n"),
},
err: nil,
expected: []byte("A\n"),
},
{
about: "sort with argucment",
job: ExecJob{
args: []string{"sort", "-n"},
data: []byte("101\n102\n999\n-9\n"),
},
err: nil,
expected: []byte("-9\n101\n102\n999\n"),
},
{
about: "simple cat1",
job: ExecJob{
args: []string{"non-existing-command"},
data: []byte("A\n"),
},
err: &os.PathError{"write", "|1", errors.New("bad file descriptor")},
expected: []byte(""),
},
// TODO(qiuyu): stderr test
}
for _, c := range testCases {
err := c.job.execute()
switch err.(type) {
case error:
if err.Error() != c.err.Error() {
t.Errorf("testcase: %s, expected - %T got - %T", c.about, c.err, err)
}
default:
if !bytes.Equal(c.expected, c.job.GetResult()) {
t.Errorf("testcase: %s, expected - %v got - %v", c.about, c.expected, c.job.GetResult())
}
}
}
}