util

package
v0.3.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LocalContext string

Functions

func Contain

func Contain(container []interface{}, i interface{}) bool

Contain will return true if a slice contains a a value

func LoadYAML

func LoadYAML(y []byte, p interface{})

LoadYAML Loads YAML into a given object

func RegexpNamedCaptures

func RegexpNamedCaptures(r *regexp.Regexp, s string) []map[string]string

RegexpNamedCaptures Helper function for getting named captures out into a map in a sane way from a multiline regex i.e. [

{
	"capture1": "hello",
	"capture2": "dylan"
},
{
	"capture1": "hello",
	"capture2": "francis"
},

]

func Run

func Run(args []string) []byte

Run runs a command and returns only the bytemap, panicing on error

Accepts an array of strings which will be joined by spaces

func RunItemValidationTest

func RunItemValidationTest(t *testing.T, i *sdp.Item)

RunItemValidationTest Checks an item to ensure it is a valid SDP item. This includes checking that all required attributes are populated

func RunSourceTests

func RunSourceTests(t *testing.T, tests []SourceTest, source discovery.Source)

func Validate

func Validate(validValues interface{}, value interface{}, errorString string)

Validate checks a value against a list of valid values and will panic with a supplied error if the values is invalid

Types

type ExpectedError

type ExpectedError struct {
	// The expected type of the error
	Type sdp.ItemRequestError_ErrorType

	// A pointer to a regex that will be used to validate the error message,
	// leave as `nil`if you don't want to check this
	ErrorStringRegex *regexp.Regexp

	// The context that the error should come from. Leave as "" if you don't
	// want to check this
	Context string
}

type ExpectedItems

type ExpectedItems struct {
	// The expected number of items
	NumItems int

	// A list of expected attributes for the items, will be checked in order
	// with the first set of attributes neeing to match those of the first item
	// etc. Note that this doesn't need to have the same number of entries as
	// there are items
	ExpectedAttributes []map[string]interface{}
}

type SourceTest

type SourceTest struct {
	// Name of the test for logging
	Name string
	// The context to be passed to the Get() request
	ItemContext string
	// The query to be passed
	Query string
	// The method that should be used
	Method sdp.RequestMethod
	// Details of the expected error, `nil` means no error
	ExpectedError *ExpectedError
	// The expected items
	ExpectedItems *ExpectedItems
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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