in pkg/testing/define/define.go [142:231]
func runOrSkip(t *testing.T, req Requirements, local bool, kubernetes bool) *Info {
// always validate requirement is valid
if err := req.Validate(); err != nil {
panic(fmt.Sprintf("test %s has invalid requirements: %s", t.Name(), err))
}
filteredGroups := GroupsFilter.values
if len(filteredGroups) > 0 && !slices.Contains(filteredGroups, req.Group) {
t.Skipf("group %s not found in groups filter %s. Skipping", req.Group, filteredGroups)
return nil
}
if SudoFilter.value != nil && req.Sudo != *SudoFilter.value {
t.Skipf("sudo requirement %t not matching sudo filter %t. Skipping", req.Sudo, *SudoFilter.value)
}
if FipsFilter.value != nil && req.FIPS != *FipsFilter.value {
t.Skipf("FIPS requirement %t not matching FIPS filter %t. Skipping.", req.FIPS, *FipsFilter.value)
}
// record autodiscover after filtering by group and sudo and before validating against the actual environment
if AutoDiscover {
discoverTest(t, req)
}
if !req.Local && local {
t.Skip("running local only tests and this test doesn't support local")
return nil
}
for _, o := range req.OS {
if o.Type == Kubernetes && !kubernetes {
t.Skip("test requires kubernetes")
return nil
}
}
if req.Sudo {
// we can run sudo tests if we are being executed as root
root, err := utils.HasRoot()
if err != nil {
panic(fmt.Sprintf("test %s failed to determine if running as root: %s", t.Name(), err))
}
if !root {
t.Skip("not running as root and test requires root")
return nil
}
}
// need OS info to determine if the test can run
osInfo, err := getOSInfo()
if err != nil {
panic("failed to get OS information")
}
dockerVariant := os.Getenv("DOCKER_VARIANT")
if !req.runtimeAllowed(runtime.GOOS, runtime.GOARCH, osInfo.Version, osInfo.Platform, dockerVariant) {
t.Skipf("platform: %s, architecture: %s, version: %s, and distro: %s combination is not supported by test. required: %v", runtime.GOOS, runtime.GOARCH, osInfo.Version, osInfo.Platform, req.OS)
return nil
}
if DryRun {
return dryRun(t, req)
}
namespace, err := getNamespace(t, local)
if err != nil {
panic(err)
}
info := &Info{
Namespace: namespace,
}
if req.Stack != nil {
info.ESClient, err = getESClient()
if err != nil {
if local {
t.Skipf("test requires a stack but failed to create a valid client to elasticsearch: %s", err)
return nil
}
// non-local test and stack was required
panic(err)
}
info.KibanaClient, err = getKibanaClient()
if err != nil {
if local {
t.Skipf("test requires a stack but failed to create a valid client to kibana: %s", err)
return nil
}
// non-local test and stack was required
panic(err)
}
}
return info
}