mockssh

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

mockssh implements a basic ssh server for use in unit tests.

Command execution in the server is implemented by a user provided handler function rather than executing a real shell.

Some inspiration is taken from but not based on: https://godoc.org/github.com/gliderlabs/ssh

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockClient

func NewMockClient(handler SessionHandler) *ssh.Client

NewMockClient starts a ssh server backed by the given handler and returns a client that is connected to it.

Types

type Session

type Session struct {
	Exec   string   // Command to execute.
	Env    []string // Environment values provided by the client.
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	// contains filtered or unexported fields
}

Session represents the server side execution of the client's ssh.Session.

func (*Session) Close

func (s *Session) Close() error

Close ends the session without sending an exit status.

func (*Session) Exit

func (s *Session) Exit(code int) error

Exit sends the given command exit status and closes the session.

type SessionHandler

type SessionHandler func(session *Session)

SessionHandler is a user provided function that processes/executes the command given to it in the given Session. Before finishing the handler must call session.Close or session.Exit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL