|
|
|
|
@ -10,32 +10,7 @@ import (
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Option is a func that sets optional attributes for a call. This does not need
|
|
|
|
|
// to be used directly, but instead option arguments are built from the
|
|
|
|
|
// functions in this package. WithX options set a value to that given in the
|
|
|
|
|
// argument; DefaultX options indicate that the value should be set to its
|
|
|
|
|
// default. When an API call is made options are processed in ther order they
|
|
|
|
|
// appear in the function call, so for a given argument X, a succession of WithX
|
|
|
|
|
// or DefaultX calls will result in the last call taking effect.
|
|
|
|
|
type Option func(*options)
|
|
|
|
|
|
|
|
|
|
type options struct {
|
|
|
|
|
withArgs []string
|
|
|
|
|
withPipe []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getOpts(opt ...Option) options {
|
|
|
|
|
opts := options{}
|
|
|
|
|
for _, o := range opt {
|
|
|
|
|
if o != nil {
|
|
|
|
|
o(&opts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return opts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandResult encapsulates the output from running an external command
|
|
|
|
|
// CommandResult captures the output from running an external command
|
|
|
|
|
type CommandResult struct {
|
|
|
|
|
Stdout []byte
|
|
|
|
|
Stderr []byte
|
|
|
|
|
@ -75,22 +50,6 @@ func RunCommand(ctx context.Context, name string, args ...string) *CommandResult
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithArgs is an option to RunCommand that allows the user to specify arguments
|
|
|
|
|
// for the provided command
|
|
|
|
|
func WithArgs(args ...string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withArgs = args
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WithPipe is an option to RunCommand that allows the user to specify a command+arguments
|
|
|
|
|
// to pipe to
|
|
|
|
|
func WithPipe(command ...string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withPipe = command
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MaybeSkipTest is a check used at the start of the test to determine if the test should run
|
|
|
|
|
func MaybeSkipTest(t testing.TB) {
|
|
|
|
|
if _, ok := os.LookupEnv(EnvToCheckSkip); !ok {
|
|
|
|
|
|