-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsession_test.go
70 lines (64 loc) · 1.37 KB
/
session_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
// +build ignore
package main
import (
"io"
"log"
"os/exec"
"reflect"
"testing"
)
func TestSessionStart(t *testing.T) {
cmd := exec.Command("./webexec", "session", "start")
in, err := cmd.StdinPipe()
if err != nil {
log.Panicf("failed to open cmd stdin: %v", err)
}
out, err := cmd.StdoutPipe()
if err != nil {
log.Panicf("failed to open cmd stdout: %v", err)
}
cmd.Start()
in.Write([]byte("e 1 80x24 cat <<EOF\n"))
in.Write([]byte("i 1 World\nEOF\n"))
b := make([]byte, 1024)
var r []byte
for {
l, e := out.Read(b)
if e == io.EOF {
break
}
if l > 0 {
if string(b[:4]) == "o 1 " {
r = append(r, b[4:l]...)
} else {
t.Fatalf("got wrong message suffix: %q", string(b[:l]))
}
}
}
if reflect.DeepEqual(r, []byte("Hello\nWorld")) {
t.Fatalf("got wrong stdout: %v", r)
}
}
func TestResize(t *testing.T) {
out := bytes.NewBufferString("")
s := SessionServer{123, out}
s.Process("e 123 34x56 echo $(tput cols)x$(tput lines)")
if out.String() != "o 123 34x56" {
t.Fail()
}
out.Reset()
// now let's resize
s.Process("r 123 12x78")
s.Process("i 123 echo $(tput cols)x$(tput lines)")
if out.String() != "o 123 12x78" {
t.Fail()
}
}
func TestKill(t *testing.T) {
out := bytes.NewBufferString("")
s := SessionServer{123, out}
// start a shell
s.Process("e 123 34x56")
s.Process("k 123")
// How do we test the process is killed?
}