Documentation ¶
Index ¶
- Variables
- func BuildBaseEvent(namespace string, options ...CommonDataOption) eventtypes.Event
- func BuildBaseEventK8s(namespace string, options ...CommonDataOption) eventtypes.Event
- func BuildCommonData(namespace string, options ...CommonDataOption) eventtypes.CommonData
- func BuildCommonDataK8s(namespace string, options ...CommonDataOption) eventtypes.CommonData
- func CheckNamespace(ns string) bool
- func ExpectAllInArrayToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntry *T)
- func ExpectAllInMultipleArrayToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntry *T)
- func ExpectAllToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntry *T)
- func ExpectEntriesInArrayToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntries ...*T)
- func ExpectEntriesInArrayToMatchObj(t *testing.T, output string, normalize func(map[string]interface{}), ...)
- func ExpectEntriesInMultipleArrayToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntries ...*T)
- func ExpectEntriesInMultipleArrayToMatchObj(t *testing.T, output string, normalize func(map[string]interface{}), ...)
- func ExpectEntriesToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntries ...*T)
- func ExpectEntriesToMatchObj(t *testing.T, output string, normalize func(map[string]interface{}), ...)
- func GenerateTestNamespaceName(namespace string) string
- func GetIPVersion(t *testing.T, address string) uint8
- func GetPodIPsFromLabel(t *testing.T, ns string, label string) []string
- func GetPodNode(t *testing.T, ns string, podname string) string
- func GetPodUID(t *testing.T, ns, podname string) string
- func GetSeed() int64
- func GetTestPodIP(t *testing.T, ns string, podname string) string
- func IsDockerRuntime(t *testing.T) bool
- func MergeJsonObjs(t *testing.T, base map[string]interface{}, ...) map[string]interface{}
- func PrintLogsFn(namespaces ...string) func(t *testing.T)
- func RunEventToObj(t *testing.T, ev *runtypes.Event) map[string]interface{}
- func RunTestSteps(steps []TestStep, t *testing.T, options ...Option)
- func SetEventK8sContainer(jsonObj map[string]interface{}, s string)
- func SetEventK8sHostNetwork(jsonObj map[string]interface{}, b bool)
- func SetEventK8sNamespace(jsonObj map[string]interface{}, s string)
- func SetEventK8sNode(jsonObj map[string]interface{}, s string)
- func SetEventK8sPod(jsonObj map[string]interface{}, s string)
- func SetEventRuntimeContainerID(jsonObj map[string]interface{}, s string)
- func SetEventRuntimeContainerName(jsonObj map[string]interface{}, s string)
- func SetEventRuntimeName(jsonObj map[string]interface{}, runtimeName eventtypes.RuntimeName)
- func StartRegistry(t *testing.T, name string) testutils.Container
- func WithCbBeforeCleanup(f func(t *testing.T)) func(opts *runTestStepsOpts)
- func WithCleanup() containerOption
- func WithContainerImage(image string) containerOption
- func WithContainerSeccompProfile(profile string) containerOption
- func WithStartAndStop() containerOption
- type Command
- func BusyboxPodCommand(namespace, cmd string) *Command
- func BusyboxPodRepeatCommand(namespace, cmd string) *Command
- func CreateTestNamespaceCommand(namespace string) *Command
- func DeleteRemainingNamespacesCommand() *Command
- func DeleteTestNamespaceCommand(namespace string) *Command
- func DeployInspektorGadget(image, imagePullPolicy string) *Command
- func DeploySPO(limitReplicas, patchWebhookConfig, bestEffortResourceMgmt bool) *Command
- func JobCommand(jobname, image, namespace, command string, commandArgs ...string) *Command
- func PodCommand(podname, image, namespace, command, commandArgs string) *Command
- func SleepForSecondsCommand(seconds int) *Command
- func WaitUntilJobCompleteCommand(namespace string, jobname string) *Command
- func WaitUntilPodReadyCommand(namespace string, podname string) *Command
- func WaitUntilPodReadyOrOOMKilledCommand(namespace string, podname string) *Command
- func WaitUntilTestPodReadyCommand(namespace string) *Command
- func WaitUntilTestPodReadyOrOOMKilledCommand(namespace string) *Command
- func (c *Command) IsCleanup() bool
- func (c *Command) IsStartAndStop() bool
- func (c *Command) KillWithoutTest() error
- func (c *Command) Run(t *testing.T)
- func (c *Command) RunWithoutTest() error
- func (c *Command) Running() bool
- func (c *Command) Start(t *testing.T)
- func (c *Command) StartWithoutTest() error
- func (c *Command) Stop(t *testing.T)
- func (c *Command) WaitWithoutTest() error
- type CommonDataOption
- type ContainerFactory
- type ContainerdContainer
- type ContainerdManager
- type DockerContainer
- type DockerManager
- type Option
- type TestComponent
- type TestStep
Constants ¶
This section is empty.
Variables ¶
var CleanupInspektorGadget = &Command{ Name: "CleanupInspektorGadget", Cmd: "$KUBECTL_GADGET undeploy", Cleanup: true, }
CleanupInspektorGadget cleans up inspector gadget in Kubernetes
var CleanupSPO = []*Command{ { Name: "RemoveSecurityProfilesOperator", Cmd: ` kubectl delete seccompprofile --all --all-namespaces kubectl delete -f https://raw.githubusercontent.com/kubernetes-sigs/security-profiles-operator/v0.6.0/deploy/operator.yaml --ignore-not-found kubectl delete -f https://github.com/jetstack/cert-manager/releases/download/v1.10.0/cert-manager.yaml --ignore-not-found `, Cleanup: true, }, { Name: "PatchSecurityProfilesOperatorProfiles", Cmd: ` while true; do # Ensure we have profiles to clean, otherwise just exit. NAMESPACES=$(kubectl get seccompprofile --all-namespaces --no-headers --ignore-not-found -o custom-columns=":metadata.namespace" | uniq) if [ -z $NAMESPACES ]; then break fi # Patch profiles in each namespace, ignore any errors since it can already be deleted. for NAMESPACE in $NAMESPACES; do PROFILES=$(kubectl get seccompprofile --namespace $NAMESPACE -o name) for PROFILE in $PROFILES; do kubectl patch $PROFILE -n $NAMESPACE -p '{"metadata":{"finalizers":null}}' --type=merge || true done done # Give some time before starting next cycle. sleep 1 done `, Cleanup: true, }, }
CleanupSPO cleans up security profile operator in Kubernetes
var DefaultTestComponent = InspektorGadgetTestComponent
DefaultTestComponent indicates component under testing allowing component specific logic e.g. indicating whether we have to enrich error message with InspektorGadget logs
Functions ¶
func BuildBaseEvent ¶
func BuildBaseEvent(namespace string, options ...CommonDataOption) eventtypes.Event
func BuildBaseEventK8s ¶ added in v0.26.0
func BuildBaseEventK8s(namespace string, options ...CommonDataOption) eventtypes.Event
func BuildCommonData ¶
func BuildCommonData(namespace string, options ...CommonDataOption) eventtypes.CommonData
func BuildCommonDataK8s ¶ added in v0.26.0
func BuildCommonDataK8s(namespace string, options ...CommonDataOption) eventtypes.CommonData
func CheckNamespace ¶ added in v0.11.0
func ExpectAllInArrayToMatch ¶
func ExpectAllInArrayToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntry *T)
ExpectAllInArrayToMatch verifies that the expectedEntry is matched by all the entries in the output (JSON array of JSON objects).
func ExpectAllInMultipleArrayToMatch ¶ added in v0.13.0
func ExpectAllInMultipleArrayToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntry *T)
ExpectAllInMultipleArrayToMatch verifies that the expectedEntry is matched by all the entries in the output (multiple JSON array of JSON objects separated by newlines).
func ExpectAllToMatch ¶
ExpectAllToMatch verifies that the expectedEntry is matched by all the entries in the output (Lines of independent JSON objects).
func ExpectEntriesInArrayToMatch ¶
func ExpectEntriesInArrayToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntries ...*T)
ExpectEntriesInArrayToMatch verifies that all the entries in expectedEntries are matched by at least one entry in the output (JSON array of JSON objects).
func ExpectEntriesInArrayToMatchObj ¶ added in v0.22.0
func ExpectEntriesInArrayToMatchObj(t *testing.T, output string, normalize func(map[string]interface{}), expectedEntries ...map[string]interface{})
ExpectEntriesInArrayToMatchObj verifies that all the entries in expectedEntries are matched by at least one entry in the output (JSON array of JSON objects).
func ExpectEntriesInMultipleArrayToMatch ¶ added in v0.13.0
func ExpectEntriesInMultipleArrayToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntries ...*T)
ExpectEntriesInMultipleArrayToMatch verifies that all the entries in expectedEntries are matched by at least one entry in the output (multiple JSON array of JSON objects separated by newlines).
func ExpectEntriesInMultipleArrayToMatchObj ¶ added in v0.26.0
func ExpectEntriesInMultipleArrayToMatchObj( t *testing.T, output string, normalize func(map[string]interface{}), expectedEntries ...map[string]interface{}, )
ExpectEntriesInMultipleArrayToMatchObj verifies that all the entries in expectedEntries are matched by at least one entry in the output (multiple JSON array of JSON objects separated by newlines).
func ExpectEntriesToMatch ¶
func ExpectEntriesToMatch[T any](t *testing.T, output string, normalize func(*T), expectedEntries ...*T)
ExpectEntriesToMatch verifies that all the entries in expectedEntries are matched by at least one entry in the output (Lines of independent JSON objects).
func ExpectEntriesToMatchObj ¶ added in v0.19.0
func ExpectEntriesToMatchObj(t *testing.T, output string, normalize func(map[string]interface{}), expectedEntries ...map[string]interface{})
ExpectEntriesToMatchObj verifies that all the entries in expectedEntries are matched by at least one entry in the output (Lines of independent JSON objects).
func GenerateTestNamespaceName ¶
GenerateTestNamespaceName returns a string which can be used as unique namespace. The returned value is: namespace_parameter-random_integer.
func GetIPVersion ¶ added in v0.21.0
GetIPVersion returns the version of the IP, 4 or 6. It makes the test fail in case of error. Based on https://stackoverflow.com/a/48519490
func GetPodIPsFromLabel ¶ added in v0.17.0
func IsDockerRuntime ¶ added in v0.19.0
IsDockerRuntime checks whether the container runtime of the first node in the Kubernetes cluster is Docker or not.
func MergeJsonObjs ¶ added in v0.19.0
func MergeJsonObjs(t *testing.T, base map[string]interface{}, additionalFields map[string]interface{}) map[string]interface{}
MergeJsonObjs merges two JSON objects (map[string]interface{}) and returns a copy. The original objects are not modified in order to use the base for multiple merges. If a key exists in both objects, the function fails.
func PrintLogsFn ¶ added in v0.14.0
PrintLogsFn returns a function that print logs in case the test fails.
func RunEventToObj ¶ added in v0.19.0
func RunTestSteps ¶ added in v0.12.0
RunTestSteps is used to run a list of test steps with stopping/clean up logic. executeBeforeCleanup is executed before calling the cleanup functions, it can be use for instance to print extra logs when the test fails.
func SetEventK8sContainer ¶ added in v0.19.0
func SetEventK8sHostNetwork ¶ added in v0.19.0
func SetEventK8sNamespace ¶ added in v0.19.0
func SetEventK8sNode ¶ added in v0.19.0
func SetEventK8sPod ¶ added in v0.19.0
func SetEventRuntimeContainerID ¶ added in v0.19.0
func SetEventRuntimeContainerName ¶ added in v0.19.0
func SetEventRuntimeName ¶ added in v0.19.0
func SetEventRuntimeName(jsonObj map[string]interface{}, runtimeName eventtypes.RuntimeName)
func StartRegistry ¶ added in v0.25.0
func WithCbBeforeCleanup ¶ added in v0.14.0
func WithCleanup ¶ added in v0.20.0
func WithCleanup() containerOption
func WithContainerImage ¶ added in v0.18.0
func WithContainerImage(image string) containerOption
func WithContainerSeccompProfile ¶ added in v0.18.0
func WithContainerSeccompProfile(profile string) containerOption
func WithStartAndStop ¶ added in v0.20.0
func WithStartAndStop() containerOption
Types ¶
type Command ¶
type Command struct { // Name of the command to be run, used to give information. Name string // Cmd is a string of the command which will be run. Cmd string // ExpectedString contains the exact expected output of the command. ExpectedString string // ExpectedRegexp contains a regex used to match against the command output. ExpectedRegexp string // ValidateOutput is a function used to verify the output. It must make the test fail in // case of error. ValidateOutput func(t *testing.T, output string) // Cleanup indicates this command is used to clean resource and should not be // skipped even if previous commands failed. Cleanup bool // StartAndStop indicates this command should first be started then stopped. // It corresponds to gadget like execsnoop which wait user to type Ctrl^C. StartAndStop bool // contains filtered or unexported fields }
func BusyboxPodCommand ¶
BusyboxPodCommand returns a Command that creates a pod and runs "cmd" in it.
func BusyboxPodRepeatCommand ¶
BusyboxPodRepeatCommand returns a Command that creates a pod and runs "cmd" each 0.1 seconds inside the pod.
func CreateTestNamespaceCommand ¶
CreateTestNamespaceCommand returns a Command which creates a namespace whom name is given as parameter.
func DeleteRemainingNamespacesCommand ¶
func DeleteRemainingNamespacesCommand() *Command
DeleteRemainingNamespacesCommand returns a Command which deletes a namespace whom name is given as parameter.
func DeleteTestNamespaceCommand ¶
DeleteTestNamespaceCommand returns a Command which deletes a namespace whom name is given as parameter.
func DeployInspektorGadget ¶
DeployInspektorGadget deploys inspector gadget in Kubernetes
func JobCommand ¶ added in v0.23.0
JobCommand returns a Command which runs a job with a specified image, command and args
func PodCommand ¶
PodCommand returns a Command that starts a pod with a specified image, command and args
func SleepForSecondsCommand ¶ added in v0.11.0
SleepForSecondsCommand returns a Command which sleeps for given seconds
func WaitUntilJobCompleteCommand ¶ added in v0.23.0
WaitUntilJobCompleteCommand returns a Command which waits until the job with the specified name in the given namespace is complete.
func WaitUntilPodReadyCommand ¶
WaitUntilPodReadyCommand returns a Command which waits until pod with the specified name in the given as parameter namespace is ready.
func WaitUntilPodReadyOrOOMKilledCommand ¶ added in v0.27.0
WaitUntilPodReadyOrOOMKilledCommand returns a Command which waits until pod with the specified name in the given as parameter namespace is ready or was oomkilled.
func WaitUntilTestPodReadyCommand ¶
WaitUntilTestPodReadyCommand returns a Command which waits until test-pod in the given as parameter namespace is ready.
func WaitUntilTestPodReadyOrOOMKilledCommand ¶ added in v0.27.0
WaitUntilTestPodReadyOrOOMKilledCommand returns a Command which waits until test-pod in the given as parameter namespace is ready or was oomkilled.
func (*Command) IsStartAndStop ¶ added in v0.12.0
func (*Command) KillWithoutTest ¶
KillWithoutTest kills a Command started with StartWithoutTest() or RunWithoutTest() and we do not need to verify its output. This is thought to be used in TestMain().
func (*Command) RunWithoutTest ¶
RunWithoutTest runs the Command, this is thought to be used in TestMain().
func (*Command) Start ¶
Start starts the Command on the given as parameter test, you need to wait it using Stop().
func (*Command) StartWithoutTest ¶
StartWithoutTest starts the Command, this is thought to be used in TestMain().
func (*Command) Stop ¶
Stop stops a Command previously started with Start(). To do so, it Kill() the process corresponding to this Cmd and then wait for its termination. Cmd output is then checked with regard to ExpectedString and ExpectedRegexp
func (*Command) WaitWithoutTest ¶
WaitWithoutTest waits for a Command that was started with StartWithoutTest(), this is thought to be used in TestMain().
type CommonDataOption ¶ added in v0.19.0
type CommonDataOption func(commonData *eventtypes.CommonData)
func WithContainerImageName ¶ added in v0.19.0
func WithContainerImageName(imageName string, isDockerRuntime bool) CommonDataOption
WithContainerImageName sets the ContainerImageName to facilitate the tests
func WithPodLabels ¶ added in v0.26.0
func WithPodLabels(podName string, namespace string, enable bool) CommonDataOption
WithPodLabels sets the PodLabels to facilitate the tests
func WithRuntimeMetadata ¶ added in v0.19.0
func WithRuntimeMetadata(runtime string) CommonDataOption
WithRuntimeMetadata sets the runtime and container name in the common data. Notice the container name is taken from the Kubernetes metadata.
type ContainerFactory ¶ added in v0.18.0
type ContainerFactory interface {
NewContainer(name, cmd string, opts ...containerOption) TestStep
}
func NewContainerFactory ¶ added in v0.18.0
func NewContainerFactory(containerRuntime string) (ContainerFactory, error)
type ContainerdContainer ¶ added in v0.18.0
ContainerdContainer implements TestStep for containerd containers
func (*ContainerdContainer) IsCleanup ¶ added in v0.18.0
func (c *ContainerdContainer) IsCleanup() bool
func (*ContainerdContainer) IsStartAndStop ¶ added in v0.18.0
func (c *ContainerdContainer) IsStartAndStop() bool
type ContainerdManager ¶ added in v0.18.0
type ContainerdManager struct{}
func (*ContainerdManager) NewContainer ¶ added in v0.18.0
func (cm *ContainerdManager) NewContainer(name, cmd string, opts ...containerOption) TestStep
type DockerContainer ¶ added in v0.12.0
DockerContainer implements TestStep for docker containers
func (*DockerContainer) IsCleanup ¶ added in v0.12.0
func (d *DockerContainer) IsCleanup() bool
func (*DockerContainer) IsStartAndStop ¶ added in v0.12.0
func (d *DockerContainer) IsStartAndStop() bool
type DockerManager ¶ added in v0.18.0
type DockerManager struct{}
func (*DockerManager) NewContainer ¶ added in v0.18.0
func (dm *DockerManager) NewContainer(name, cmd string, opts ...containerOption) TestStep
type TestComponent ¶ added in v0.12.0
type TestComponent string
const ( InspektorGadgetTestComponent TestComponent = "$KUBECTL_GADGET" IgTestComponent TestComponent = "ig" )
type TestStep ¶ added in v0.12.0
type TestStep interface { // Run runs the step and wait its completion. Run(t *testing.T) // Start starts the step and immediately returns, it does wait until // its completion, use Stop() for that. Start(t *testing.T) // Stop stops the step and waits its completion. Stop(t *testing.T) // IsCleanup returns true if the step is used to clean resource and // should not be skipped even if previous commands failed. IsCleanup() bool // IsStartAndStop returns true if the step should first be started then // stopped after some time. IsStartAndStop() bool // Running returns true if the step has been started. Running() bool }
TestStep allows combining different steps (e.g command, container creation) to allow simplified/consistent flow for tests via RunTestSteps