| 251 | } |
| 252 | |
| 253 | func (c *testContext) StartSessionChannel() { |
| 254 | t := c.T |
| 255 | t.Helper() |
| 256 | c.lock.Lock() |
| 257 | defer c.lock.Unlock() |
| 258 | if c.sshConn == nil { |
| 259 | t.Fatalf("SSH connection is not running.") |
| 260 | } |
| 261 | if c.channel != nil { |
| 262 | t.Fatalf("A channel is already open.") |
| 263 | } |
| 264 | |
| 265 | t.Logf("Starting a new session channel...") |
| 266 | |
| 267 | channel, requests, err := c.sshConn.OpenChannel("session", nil) |
| 268 | if err != nil { |
| 269 | t.Fatalf("Failed to open channel (%v)", err) |
| 270 | } |
| 271 | c.channel = channel |
| 272 | c.requests = requests |
| 273 | // We use c.T here so the cleanup happens in the parent test. |
| 274 | c.T.Cleanup(func() { |
| 275 | _ = channel.Close() |
| 276 | c.channel = nil |
| 277 | }) |
| 278 | |
| 279 | t.Logf("Started a new session channel.") |
| 280 | } |
| 281 | |
| 282 | func (c *testContext) RequestCommandExecution(cmd string) { |
| 283 | t := c.T |