blob: 7e0795613187da1e368c4a60bbf30caaf2d05ab9 (
plain)
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
|
package config
import "testing"
func TestCommandValidate(t *testing.T) {
// Empty command
if err := validateCommand(""); err == nil {
t.Fatal("An command cannot be empty")
}
// invalid command
if err := validateCommand("invalid"); err == nil {
t.Fatal("An command cannot be empty")
}
// cp
if err := validateCommand("cp"); err == nil {
t.Fatal("cp command needs arguments")
}
if err := validateCommand("cp test"); err == nil {
t.Fatal("cp command needs exactly 2 arguments")
}
if err := validateCommand("cp test test test"); err == nil {
t.Fatal("cp command needs exactly 2 arguments")
}
if err := validateCommand("exec test test"); err != nil {
t.Fatal("valid exec command should be accepted")
}
// exec
if err := validateCommand("exec"); err == nil {
t.Fatal("exec command needs arguments")
}
if err := validateCommand("exec test"); err != nil {
t.Fatal("valid exec command should be accepted")
}
// mkdir
if err := validateCommand("mkdir"); err == nil {
t.Fatal("mkdir command needs exactly 1 argument")
}
if err := validateCommand("mkdir testtest "); err == nil {
t.Fatal("mkdir command needs exactly 1 argument")
}
if err := validateCommand("mkdir test"); err != nil {
t.Fatal("valid mkdir command should be accepted")
}
// wait
if err := validateCommand("wait test"); err == nil {
t.Fatal("wait command needs no arguments")
}
if err := validateCommand("wait"); err != nil {
t.Fatal("valid wait command should be accepted")
}
}
|