ssh

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 15 Imported by: 5

README

Venom - Executor SSH

Step for execute a script on remote server via SSH

Input

In your yaml file, you can use:

  - host mandatory
  - command mandatory
  - user optional (default is OS username)
  - password optional (mandatory if no privatekey is found)
  - privatekey optional (default is $HOME/.ssh/id_rsa)
  - sudo optional
  - sudopassword optional (default to password)

Example


name: Title of TestSuite
testcases:
- name: Check if exit code != 1 and echo command response in less than 1s
  steps:
  - type: ssh
    host: localhost:2222
    command: echo 'foo'
    assertions:
    - result.code ShouldEqual 0
    - result.timeseconds ShouldBeLessThan 1

- name: Use specific privatekey
  steps:
  - type: ssh
    host: 10.0.1.5:2222
    command: echo 'foo'
    user: bar
    privatekey: /home/foo/.ssh/id_rsa
    assertions:
    - result.code ShouldEqual 0

- name: Execute command as another user than bar
  steps:
  - type: ssh
    host: 10.0.1.5:2222
    command: echo 'foo'
    user: bar
    sudo: root
    sudopassword: '{{.mypassword}}'
    assertions:
    - result.code ShouldEqual 0

NB: Sudo option uses a pseudotty

Output

systemout
systemerr
err
code
timeseconds
  • result.timeseconds: time of execution
  • result.err: if exists, this field contains error
  • result.systemout: Standard Output of executed script
  • result.systemerr: Error Output of executed script
  • result.code: Exit Code

Default assertion

result.code ShouldEqual 0

Documentation

Index

Constants

View Source
const Name = "ssh"

Name for test ssh

Variables

This section is empty.

Functions

func New

func New() venom.Executor

New returns a new Test Exec

Types

type Buffer added in v1.1.0

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer thread safe

func (*Buffer) Bytes added in v1.1.0

func (b *Buffer) Bytes() []byte

Bytes thread safe

func (*Buffer) Len added in v1.1.0

func (b *Buffer) Len() int

Len thread safe

func (*Buffer) Read added in v1.1.0

func (b *Buffer) Read(p []byte) (n int, err error)

Read thread safe

func (*Buffer) String added in v1.1.0

func (b *Buffer) String() string

String thread safe

func (*Buffer) Truncate added in v1.1.0

func (b *Buffer) Truncate(n int)

Truncate thread safe

func (*Buffer) Write added in v1.1.0

func (b *Buffer) Write(p []byte) (n int, err error)

Write thread safe

type Executor

type Executor struct {
	Host         string `json:"host,omitempty" yaml:"host,omitempty"`
	Command      string `json:"command,omitempty" yaml:"command,omitempty"`
	User         string `json:"user,omitempty" yaml:"user,omitempty"`
	Password     string `json:"password,omitempty" yaml:"password,omitempty"`
	PrivateKey   string `json:"privatekey,omitempty" yaml:"privatekey,omitempty"`
	Sudo         string `json:"sudo,omitempty" yaml:"sudo,omitempty"`
	SudoPassword string `json:"sudopassword,omitempty" yaml:"sudopassword,omitempty"`
}

Executor represents a Test Exec

func (Executor) GetDefaultAssertions

func (Executor) GetDefaultAssertions() *venom.StepAssertions

GetDefaultAssertions return default assertions for type exec

func (Executor) Run

func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, error)

Run execute TestStep of type exec

func (Executor) ZeroValueResult added in v0.17.0

func (Executor) ZeroValueResult() interface{}

ZeroValueResult return an empty implementation of this executor result

type Result

type Result struct {
	Systemout   string  `json:"systemout,omitempty" yaml:"systemout,omitempty"`
	Systemerr   string  `json:"systemerr,omitempty" yaml:"systemerr,omitempty"`
	Err         string  `json:"err,omitempty" yaml:"err,omitempty"`
	Code        string  `json:"code,omitempty" yaml:"code,omitempty"`
	TimeSeconds float64 `json:"timeseconds,omitempty" yaml:"timeseconds,omitempty"`
}

Result represents a step result

Jump to

Keyboard shortcuts

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