This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_client.go
104 lines (74 loc) · 3.29 KB
/
test_client.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package sshserver
import (
"context"
"errors"
"io"
)
// ErrAuthenticationFailed is the error that is returned from TestClient.Connect when the authentication failed.
var ErrAuthenticationFailed = errors.New("authentication failed")
// TestClient is an SSH client intended solely for testing purposes.
type TestClient interface {
// Connect establishes a connection to the server.
Connect() (TestClientConnection, error)
// MustConnect is identical to Connect, but panics it if it cannot connect.
MustConnect() TestClientConnection
}
// TestClientConnection is an individual established connection to the server
type TestClientConnection interface {
// Session establishes a new session channel
Session() (TestClientSession, error)
//MustSession is identical to Session but panics if a session cannot be requested.
MustSession() TestClientSession
// Close closes the connection and all sessions in it.
Close() error
}
type TestClientSession interface {
// SetEnv sets an environment variable or returns with an error.
SetEnv(name string, value string) error
// MustSetEnv is identical to SetEnv, but panics if an error happens.
MustSetEnv(name string, value string)
// Window requests the terminal window to be resized to a certain size.
Window(cols int, rows int) error
// MustWindow is identical to Window, but panics if an error happens.
MustWindow(cols int, rows int)
// RequestPTY requests the server to open a PTY/TTY for this channel. Returns an error if the request failed.
RequestPTY(term string, cols int, rows int) error
// MustRequestPTY is identical to RequestPTY but panics if an error happens.
MustRequestPTY(term string, cols int, rows int)
// Signal sends a signal to the process
Signal(signal string) error
// MustSignal is equal to Signal but panics if an error happens.
MustSignal(signal string)
// Shell requests a shell to be opened. After this call returns I/O interactions are possible.
Shell() error
// MustShell is identical to Shell but panics if an error happens.
MustShell()
// Exec requests a specific program to be executed. After this call returns I/O interactions are possible.
Exec(program string) error
// MustExec is identical to Exec but panics if an error happens.
MustExec(program string)
// Subsystem requests a specific subsystem to be executed. After this call returns I/O interactions are possible.
Subsystem(name string) error
// MustSubsystem is identical to Subsystem but panics if an error happens.
MustSubsystem(name string)
// Write writes to the stdin of the session.
Write(data []byte) (int, error)
// Type writes to the stdin slowly with 50 ms delays
Type(data []byte) error
// Read reads from the stdout of the session.
Read(data []byte) (int, error)
// ReadRemaining reads the remaining bytes from stdout until EOF.
ReadRemaining()
// ReadRemainingStderr reads the remaining bytes from stderr until EOF.
ReadRemainingStderr()
// WaitForStdout waits for a specific byte sequence to appear on the stdout.
WaitForStdout(ctx context.Context, data []byte) error
// Stderr returns the reader for the stdout.
Stderr() io.Reader
// Wait waits for the session to terminate.
Wait() error
// ExitCode returns the exit code received from the session, or -1 if not received.
ExitCode() int
// Close closes the session.
Close() error
}