-
Notifications
You must be signed in to change notification settings - Fork 0
/
mole_test.go
74 lines (60 loc) · 1.49 KB
/
mole_test.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package mole
import (
"log"
"testing"
)
func TestSingleRun(t *testing.T) {
mole := NewMole()
if err := mole.Run(); err == nil {
t.Fatal("It should be occur error when Run is called with no commands")
}
mole.Add("ls", "-la")
if err := mole.Run(); err != nil {
t.Fatal("Failed to run Run() with 1 command")
}
if err := mole.Run(); err == nil {
t.Fatal("It should be occur error when Run is called multiple times")
}
}
func TestSingleOutput(t *testing.T) {
mole := NewMole()
mole.Add("ls", "-la")
out, err := mole.Output()
if err != nil {
t.Fatal("Failed to run Output() with 1 command")
}
log.Println(string(out))
_, err = mole.Output()
if err == nil {
t.Fatal("It should be occur error when Output is called multiple times")
}
}
func TestMultipleRun(t *testing.T) {
mole := NewMole()
mole.Add("ls", "-la")
mole.Add("head", "-5")
mole.Add("wc", "-l")
mole.Add("tr", "-d", " ")
if err := mole.Run(); err != nil {
t.Fatal("Failed to run Run() with 4 command")
}
if err := mole.Run(); err == nil {
t.Fatal("It should be occur error when Run is called multiple times")
}
}
func TestMultipleOutput(t *testing.T) {
mole := NewMole()
mole.Add("ls", "-la")
mole.Add("head", "-5")
mole.Add("wc", "-l")
mole.Add("tr", "-d", " ")
out, err := mole.Output()
if err != nil {
t.Fatal("Failed to run Output() with 1 command")
}
log.Println(string(out))
_, err = mole.Output()
if err == nil {
t.Fatal("It should be occur error when Output is called multiple times")
}
}