expect

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package expect implements a small expect-style interface

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProcessRunning = errors.New("process is still running")
)

Functions

This section is empty.

Types

type Process

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

func New

func New(name string, arg ...string) (ep *Process, err error)

New creates a new process for expect testing.

func NewWithEnv

func NewWithEnv(name string, args []string, env []string, serverProcessConfigName string) (ep *Process, err error)

NewWithEnv creates a new process with user defined env variables for expect testing.

func (*Process) Close

func (ep *Process) Close() error

Close waits for the expect process to exit and return its error.

func (*Process) ExitCode

func (ep *Process) ExitCode() (int, error)

ExitCode returns the exit code of this process. If the process is still running, it returns exit code 0 and ErrProcessRunning.

func (*Process) ExitError

func (ep *Process) ExitError() error

ExitError returns the exit error of this process (if any). If the process is still running, it returns ErrProcessRunning instead.

func (*Process) Expect

func (ep *Process) Expect(s string) (string, error)

Expect returns the first line containing the given string. Deprecated: please use ExpectWithContext instead.

func (*Process) ExpectFunc

func (ep *Process) ExpectFunc(ctx context.Context, f func(string) bool) (string, error)

ExpectFunc returns the first line satisfying the function f.

func (*Process) ExpectWithContext

func (ep *Process) ExpectWithContext(ctx context.Context, s Response) (string, error)

ExpectWithContext returns the first line containing the given string.

func (*Process) LineCount

func (ep *Process) LineCount() int

LineCount returns the number of recorded lines since the beginning of the process.

func (*Process) Lines

func (ep *Process) Lines() []string

func (*Process) PID

func (ep *Process) PID() int

func (*Process) ReadLine

func (ep *Process) ReadLine() string

ReadLine returns line by line.

func (*Process) Send

func (ep *Process) Send(command string) error

func (*Process) Signal

func (ep *Process) Signal(sig os.Signal) error

Signal sends a signal to the expect process

func (*Process) Stop

func (ep *Process) Stop() error

Stop signals the process to terminate via SIGTERM

func (*Process) Wait

func (ep *Process) Wait()

Wait waits for the process to finish.

type Response

type Response struct {
	Value         string
	IsRegularExpr bool
}

Jump to

Keyboard shortcuts

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