testingutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const TestTag = "test"

Variables

This section is empty.

Functions

func AssertEqualsField

func AssertEqualsField(t *testing.T, a, b model.Field)

func AssertEqualsResource

func AssertEqualsResource(t *testing.T, a, b model.Resource)

func AssertEqualsResourcePter

func AssertEqualsResourcePter(t *testing.T, a, b *model.Resource)

func AssertEqualsResources

func AssertEqualsResources(t *testing.T, a, b model.Resources)

func AssertEqualsTag

func AssertEqualsTag(t *testing.T, a, b *model.Tag)

func AssertEqualsTags

func AssertEqualsTags(t *testing.T, a, b model.Tags)

func AssertEvent added in v0.0.11

func AssertEvent(t *testing.T, ee, ae model.Event)

func AssertResourceCount

func AssertResourceCount(t TestingTB, resources []model.Resource, tagValue string, count int)

AssertResourceCount asserts that there is a specific number of given resources with the "test" tag. If tagValue is not an empty string, it also filters on resources that have the "test" tag with that value.

func AssertResourceFilteredCount

func AssertResourceFilteredCount(t TestingTB, resources []model.Resource, count int, filter ResourceFilter) []model.Resource

func FetchAll

func FetchAll[T any](ctx context.Context, t TestingTB, f func(context.Context, chan<- T) error) ([]T, error)

FetchAll pulls all resources from `f` over the passed channel, returning the resources as a slice

func FilterFunc

func FilterFunc[T any](in []T, predicate func(T) bool) []T

FilterFunc filters a slice based on the predicate function

func FuncSignature

func FuncSignature(value any) string

FuncSignature returns the signature of a function as a string, useful for error messages.

func JSONBytesEqual

func JSONBytesEqual(a, b []byte) (bool, error)

JSONBytesEqual compares the JSON in two byte slices.

func MustFetchAll

func MustFetchAll[T any](ctx context.Context, t TestingTB, f func(context.Context, chan<- T) error) []T

MustFetchAll is like FetchAll, but fatals the running test if there is an error during fetching

func ResourceFilterTagKey

func ResourceFilterTagKey(in []model.Resource, key string) []model.Resource

ResourceFilterTagKey filters a slice of model.Resources based on a given tag key being present on that resource.

func ResourceFilterTagKeyValue

func ResourceFilterTagKeyValue(in []model.Resource, key, value string) []model.Resource

ResourceFilterTagKey filters a slice of model.Resources based on a given tag key/value pair being present on that resource.

func SliceConvertFunc

func SliceConvertFunc[In any, Out any, T ~[]In](in T, f func(In) Out) []Out

func TypeStr

func TypeStr(v any) string

TypeStr is a convenience function to get the fully qualified type identifier for a value

func Unique

func Unique[T comparable](in []T) []T

Unique returns a new slice with duplicate elements removed and the order preserved.

Types

type ResourceFilter

type ResourceFilter struct {
	AccountId       string
	Region          string
	Type            string
	DisplayIdPrefix string
	Tags            model.Tags
	RawData         map[string]any
}

func (ResourceFilter) Filter

func (f ResourceFilter) Filter(in []model.Resource) []model.Resource

func (ResourceFilter) Matches

func (f ResourceFilter) Matches(resource model.Resource) bool

func (ResourceFilter) PartialFilter added in v0.2.0

func (f ResourceFilter) PartialFilter(in []model.Resource) map[string][]model.Resource

PartialFilter returns a more detailed filtering of the resources, with filter field processed separately. This can aid in debugging to determine why a resource isn't matching a given filter.

func (ResourceFilter) String

func (f ResourceFilter) String() string

type TestingTB added in v0.2.0

type TestingTB interface {
	Errorf(string, ...any)
	Fatalf(string, ...any)
	Helper()
	FailNow()
}

TestingTB is an interface wrapper around testing.TB reduced to what the funcs in testingutil need (to assist with tesing this package). Satisfies the assert.TestingT and require.TestingT interfaces

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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