-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestscenario_test.go
More file actions
51 lines (39 loc) · 1.07 KB
/
testscenario_test.go
File metadata and controls
51 lines (39 loc) · 1.07 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
package main
import (
"fmt"
"strings"
"testing"
"time"
)
func expectOutput(t *testing.T, process *ProcessBuffer, expected string) {
time.Sleep(200 * time.Millisecond)
output := string(process.Peek())
index := strings.Index(output, expected)
if index == -1 {
t.Errorf("Expected:\n%s\n", expected)
t.Errorf("Got:\n%s\n", output)
return
} else {
endIndex := index + len(expected)
process.Seek(endIndex)
}
}
func TestNewTestScenario(t *testing.T) {
process, err := NewProcessBuffer("./examples/tool.sh", []string{"arg1"})
if err != nil {
fmt.Println("Error:", err)
return
}
process.Launch()
expectOutput(t, process, "Name: ")
process.Write("AAA")
expectOutput(t, process, "Hello, AAA")
expectOutput(t, process, "Age: ")
process.Write("32")
expectOutput(t, process, "You are 32 years old")
expectOutput(t, process, "Your arg was: arg1")
process.Stop()
}
// TODO: Test what happens when the process ends early and you try to write to it
// TODO: Test how to handle when the process exit code is not 0
// Maybe I could check it before each instruction?