util

package
v0.0.0-...-ce3d181 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendError

func AppendError(errs []error, err error) []error

AppendError does append(errs, err) if err != nil

func AppendField

func AppendField(fields []string, flag, prefix string) []string

AppendField will append prefix to the flag value.

For example, AppendField(fields, "--foo", "bar") if fields is empty or does not contain a "--foo" it will simply append a "--foo=bar" value. Otherwise if fields contains "--foo=current" it will replace this value with "--foo=current-bar

func EnsureExecutable

func EnsureExecutable(p string) error

EnsureExecutable sets the executable file mode bits, for all users, to ensure that we can execute a file

func ExecError

func ExecError(err error) string

ExecError returns a string format of err including stderr if the err is an ExitError, useful for errors from e.g. exec.Cmd.Output().

func ExtractField

func ExtractField(fields []string, target string) ([]string, string, bool)

ExtractField input ("--a=this --b=that --c=other", "--b") returns [--a=this, --c=other"], "that", true

In other words, it will remove "--b" from fields and return the previous value of "--b" if it was set.

func FlushMem

func FlushMem()

FlushMem will try to reduce the memory usage of the container it is running in run this after a build

func Home

func Home(parts ...string) string

Home returns $HOME/part/part/part

func InsertPath

func InsertPath(path string) error

InsertPath does export PATH=path:$PATH

func JSONForDebug

func JSONForDebug(o interface{}) string

JSONForDebug returns a json representation of the value, or a string representation of an error It is useful for an easy implementation of fmt.Stringer

func JoinURL

func JoinURL(urlPath, path string) (string, error)

JoinURL converts input (gs://foo, "bar") to gs://foo/bar

func K8s

func K8s(topdir string, parts ...string) string

K8s returns $GOPATH/src/k8s.io/...

func MigrateOptions

func MigrateOptions(m []MigratedOption) error

MigrateOptions reads value from ENV if --flag unset, optionally pushing to ENV

func OptionalAbsPath

func OptionalAbsPath(path string) (string, error)

OptionalAbsPath returns an absolute path if the provided path wasn't empty, and otherwise returns an empty string.

func PushEnv

func PushEnv(env, value string) (func() error, error)

PushEnv pushes env=value and return a function that resets env

func Pushd

func Pushd(dir string) (func() error, error)

Pushd will Chdir() to dir and return a function to cd back to Getwd()

func SetFieldDefault

func SetFieldDefault(fields []string, flag, val string) []string

SetFieldDefault sets the value of flag to val if flag is not present in fields.

For example, SetFieldDefault(fields, "--foo", "bar") will append "--foo=bar" if fields is empty or does not include a "--foo" flag. It returns fields unchanged if "--foo" is present.

Types

type MigratedOption

type MigratedOption struct {
	Env      string  // env associated with --flag
	Option   *string // Value of --flag
	Name     string  // --flag name
	SkipPush bool    // Push option to env if false
}

MigratedOption is an option that was an ENV that is now a --flag

type TestCase

type TestCase struct {
	XMLName   xml.Name `xml:"testcase"`
	ClassName string   `xml:"classname,attr"`
	Name      string   `xml:"name,attr"`
	Time      float64  `xml:"time,attr"`
	Failure   string   `xml:"failure,omitempty"`
	Skipped   string   `xml:"skipped,omitempty"`
}

TestCase holds the result of a test/step/command.

This will become a row in testgrid.

type TestSuite

type TestSuite struct {
	XMLName  xml.Name `xml:"testsuite"`
	Failures int      `xml:"failures,attr"`
	Tests    int      `xml:"tests,attr"`
	Time     float64  `xml:"time,attr"`
	Cases    []TestCase
}

TestSuite holds a slice of TestCase and other summary metadata.

A build (column in testgrid) is composed of one or more TestSuites.

Jump to

Keyboard shortcuts

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