-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtunnel_control_test.go
More file actions
75 lines (60 loc) · 1.52 KB
/
Copy pathtunnel_control_test.go
File metadata and controls
75 lines (60 loc) · 1.52 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package sshlib
import (
"bytes"
"net"
"testing"
)
type nopTunnelLocal struct {
bytes.Buffer
}
func (n *nopTunnelLocal) Close() error {
return nil
}
func (n *nopTunnelLocal) Read(p []byte) (int, error) {
return 0, nil
}
func TestTunnelCopyControlOutputReadsFrames(t *testing.T) {
client, server := net.Pipe()
defer client.Close()
go func() {
defer server.Close()
if err := writeStreamFrame(server, streamFrameStdout, []byte("packet")); err != nil {
t.Errorf("write stdout frame: %v", err)
return
}
if err := writeStreamFrame(server, streamFrameExit, encodeExitStatus(0)); err != nil {
t.Errorf("write exit frame: %v", err)
}
}()
local := &nopTunnelLocal{}
tunnel := &Tunnel{
local: local,
done: make(chan error, 1),
}
go tunnel.copyControlOutput(local, client)
if err := tunnel.Wait(); err != nil {
t.Fatalf("Wait() error = %v, want nil", err)
}
if got := local.String(); got != "packet" {
t.Fatalf("local payload = %q, want %q", got, "packet")
}
}
func TestTunnelCopyControlOutputReturnsErrorFrame(t *testing.T) {
client, server := net.Pipe()
defer client.Close()
go func() {
defer server.Close()
if err := writeStreamFrame(server, streamFrameError, []byte("boom")); err != nil {
t.Errorf("write error frame: %v", err)
}
}()
local := &nopTunnelLocal{}
tunnel := &Tunnel{
local: local,
done: make(chan error, 1),
}
go tunnel.copyControlOutput(local, client)
if err := tunnel.Wait(); err == nil || err.Error() != "boom" {
t.Fatalf("Wait() error = %v, want boom", err)
}
}