utils

package
v0.0.0-...-253972b Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package utils - Utils for cloud testing tool

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearFolder

func ClearFolder(root string, recreate bool)

ClearFolder - If folder exists it will be removed with all subfolders and if recreate is passed it will be created

func Contains

func Contains(a []string, x string) bool

Contains - check if array contains element.

func CreateFolders

func CreateFolders(root string)

CreateFolders - Create folder and all parents.

func ExecRead

func ExecRead(ctx context.Context, dir string, args []string) ([]string, error)

ExecRead - execute command and return output as result, stderr is ignored.

func FileExists

func FileExists(root string) bool

FileExists - check if file are exists.

func FilterByPattern

func FilterByPattern(source []string, pattern string) ([]string, error)

func GetAllFiles

func GetAllFiles(dir string) []string

GetAllFiles returns all files in dir

func MatchRetestPattern

func MatchRetestPattern(patterns []string, line string) bool

MatchRetestPattern - check if retest pattern is matched in passed string

func NewLogKeeper

func NewLogKeeper() *logKeeper

NewLogKeeper - creates new instance of logrus log collector

func NewOSSignalChannel

func NewOSSignalChannel() chan os.Signal

func NewRandomStr

func NewRandomStr(size int) string

NewRandomStr - generates random string of desired length, size should be multiple of two for best result.

func OpenFile

func OpenFile(root, fileName string) (string, *os.File, error)

OpenFile - opens a file in folder and make folder parents if required.

func ParseCommandLine

func ParseCommandLine(cmdLine string) []string

ParseCommandLine - parses command line with support of "" and escaping.

func ParseScript

func ParseScript(s string) []string

ParseScript - parse multi line script and return individual commands.

func ParseVariable

func ParseVariable(variable string) (string, string, error)

ParseVariable - parses var=value variable format.

func ReadFile

func ReadFile(fileName string) ([]string, error)

ReadFile - read a file contents and return as array of strings

func RunCommand

func RunCommand(context context.Context, cmd, dir string, logger func(str string), writer *bufio.Writer, env []string, args map[string]string, returnStdout bool) (string, error)

RunCommand - run shell command and put output into file, command variables are substituted.

func SubstituteVariable

func SubstituteVariable(variable string, vars, args map[string]string) (string, error)

SubstituteVariable - perform a substitution of all ${var} $(arg) in passed string and return substitution results and error

func WriteFile

func WriteFile(root, fileName, content string)

WriteFile - write content to file inside folder

Types

type EnvVar

type EnvVar string

EnvVar provides API for access to env variable

func (EnvVar) Name

func (v EnvVar) Name() string

Name returns emv variable name

func (EnvVar) String

func (v EnvVar) String() string

func (EnvVar) StringValue

func (v EnvVar) StringValue() string

StringValue returns value of env variable as string

type ProcWrapper

type ProcWrapper struct {
	Cmd *exec.Cmd

	Stdout io.ReadCloser
	Stderr io.ReadCloser
	// contains filtered or unexported fields
}

ProcWrapper - A simple process wrapper

func ExecProc

func ExecProc(ctx context.Context, dir string, args, env []string) (*ProcWrapper, error)

ExecProc - execute shell command and return ProcWrapper

func (*ProcWrapper) ExitCode

func (w *ProcWrapper) ExitCode() int

ExitCode - wait for completion and return exit code

Jump to

Keyboard shortcuts

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