-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspy_test.go
More file actions
46 lines (37 loc) · 1.19 KB
/
spy_test.go
File metadata and controls
46 lines (37 loc) · 1.19 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
package spy
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestParseCommand(t *testing.T) {
tcs := []struct {
cmd string
name string
args []string
errExpected bool
}{
{"echo Bukola", "echo", []string{"Bukola"}, false},
{"test it works fine", "test", []string{"it", "works", "fine"}, false},
{"cat /file-path", "cat", []string{"/file-path"}, false},
{"cd ..", "cd", []string{".."}, false},
{"echo", "echo", []string{}, false},
{"echo'", "echo'", []string{}, true},
{" ", " ", []string{}, false},
{" ", " ", []string{}, false},
{"echo 'Hello, 123'", "echo", []string{"Hello, 123"}, false},
{"sh -c 'ls", "BOGUS", []string{}, true},
}
for _, tc := range tcs {
name, args, err := ParseCommand(tc.cmd)
errorReturned := (err != nil)
if errorReturned != tc.errExpected {
t.Fatalf("ParseCommand(%q): Unexpected error status: %v", tc.cmd, err)
}
if !errorReturned && tc.name != name {
t.Errorf("ParseCommand(%q): Expected command name to be %q, got: %q", tc.cmd, tc.name, name)
}
if !errorReturned && !cmp.Equal(tc.args, args) {
t.Errorf("ParseCommand(%q): Expected args to be %q, got %q", tc.cmd, tc.args, args)
}
}
}