Skip to content

Commit

Permalink
Add function to check if there is any skip configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodm committed Jun 18, 2024
1 parent e891842 commit 5f04b26
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 56 deletions.
13 changes: 3 additions & 10 deletions internal/testrunner/runners/asset/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,11 @@ func (r *tester) run(ctx context.Context) ([]testrunner.TestResult, error) {
return result.WithError(fmt.Errorf("unable to load asset loading test config file: %w", err))
}

if testConfig != nil && testConfig.Skip != nil {
logger.Warnf("skipping %s test for %s: %s (details: %s)",
TestType, r.testFolder.Package,
testConfig.Skip.Reason, testConfig.Skip.Link)
return result.WithSkip(testConfig.Skip)
}

if r.globalTestConfig.Skip != nil {
if skip := testrunner.AnySkipConfig(testConfig.Skip, r.globalTestConfig.Skip); skip != nil {
logger.Warnf("skipping %s test for %s/%s: %s (details: %s)",
TestType, r.testFolder.Package, r.testFolder.DataStream,
r.globalTestConfig.Skip.Reason, r.globalTestConfig.Skip.Link.String())
return result.WithSkip(r.globalTestConfig.Skip)
skip.Reason, skip.Link)
return result.WithSkip(skip)
}

logger.Debug("installing package...")
Expand Down
16 changes: 3 additions & 13 deletions internal/testrunner/runners/pipeline/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,11 @@ func (r *tester) runTestCase(ctx context.Context, testCaseFile string, dsPath st
}
tr.Name = tc.name

if tc.config.Skip != nil {
if skip := testrunner.AnySkipConfig(tc.config.Skip, r.globalTestConfig.Skip); skip != nil {
logger.Warnf("skipping %s test for %s/%s: %s (details: %s)",
TestType, r.testFolder.Package, r.testFolder.DataStream,
tc.config.Skip.Reason, tc.config.Skip.Link)

tr.Skipped = tc.config.Skip
return tr, nil
}

if r.globalTestConfig.Skip != nil {
logger.Warnf("skipping %s test for %s/%s: %s (details: %s)",
TestType, r.testFolder.Package, r.testFolder.DataStream,
r.globalTestConfig.Skip.Reason, r.globalTestConfig.Skip.Link.String())

tr.Skipped = r.globalTestConfig.Skip
skip.Reason, skip.Link)
tr.Skipped = skip
return tr, nil
}

Expand Down
13 changes: 3 additions & 10 deletions internal/testrunner/runners/policy/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,11 @@ func (r *tester) runTest(ctx context.Context, manager *resources.Manager, testPa

testName := testNameFromPath(testPath)

if testConfig.Skip != nil {
if skip := testrunner.AnySkipConfig(testConfig.Skip, r.globalTestConfig.Skip); skip != nil {
logger.Warnf("skipping %s test for %s/%s: %s (details: %s)",
TestType, r.testFolder.Package, r.testFolder.DataStream,
testConfig.Skip.Reason, testConfig.Skip.Link.String())
return result.WithSkip(testConfig.Skip)
}

if r.globalTestConfig.Skip != nil {
logger.Warnf("skipping %s test for %s/%s: %s (details: %s)",
TestType, r.testFolder.Package, r.testFolder.DataStream,
r.globalTestConfig.Skip.Reason, r.globalTestConfig.Skip.Link.String())
return result.WithSkip(r.globalTestConfig.Skip)
skip.Reason, skip.Link)
return result.WithSkip(skip)
}

policy := resources.FleetAgentPolicy{
Expand Down
13 changes: 3 additions & 10 deletions internal/testrunner/runners/static/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,11 @@ func (r tester) run(ctx context.Context) ([]testrunner.TestResult, error) {
return result.WithError(fmt.Errorf("unable to load asset loading test config file: %w", err))
}

if testConfig != nil && testConfig.Skip != nil {
logger.Warnf("skipping %s test for %s: %s (details: %s)",
TestType, r.testFolder.Package,
testConfig.Skip.Reason, testConfig.Skip.Link)
return result.WithSkip(testConfig.Skip)
}

if r.globalTestConfig.Skip != nil {
if skip := testrunner.AnySkipConfig(testConfig.Skip, r.globalTestConfig.Skip); skip != nil {
logger.Warnf("skipping %s test for %s/%s: %s (details: %s)",
TestType, r.testFolder.Package, r.testFolder.DataStream,
r.globalTestConfig.Skip.Reason, r.globalTestConfig.Skip.Link.String())
return result.WithSkip(r.globalTestConfig.Skip)
skip.Reason, skip.Link)
return result.WithSkip(skip)
}

pkgManifest, err := packages.ReadPackageManifestFromPackageRoot(r.packageRootPath)
Expand Down
19 changes: 6 additions & 13 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ type tester struct {

serviceStateFilePath string

globalConfig testrunner.GlobalRunnerTestConfig
globalTestConfig testrunner.GlobalRunnerTestConfig

// Execution order of following handlers is defined in runner.TearDown() method.
removeAgentHandler func(context.Context) error
Expand Down Expand Up @@ -201,7 +201,7 @@ func NewSystemTester(options SystemTesterOptions) (*tester, error) {
runSetup: options.RunSetup,
runTestsOnly: options.RunTestsOnly,
runTearDown: options.RunTearDown,
globalConfig: options.GlobalTestConfig,
globalTestConfig: options.GlobalTestConfig,
}
r.resourcesManager = resources.NewManager()
r.resourcesManager.RegisterProvider(resources.DefaultKibanaProviderName, &resources.KibanaProvider{Client: r.kibanaClient})
Expand Down Expand Up @@ -274,7 +274,7 @@ func (r *tester) String() string {
// Parallel indicates if this tester can run in parallel or not.
func (r tester) Parallel() bool {
// it is required independent Elastic Agents to run in parallel system tests
return r.runIndependentElasticAgent && r.globalConfig.Parallel
return r.runIndependentElasticAgent && r.globalTestConfig.Parallel
}

// Run runs the system tests defined under the given folder
Expand Down Expand Up @@ -1381,18 +1381,11 @@ func (r *tester) validateTestScenario(ctx context.Context, result *testrunner.Re
func (r *tester) runTest(ctx context.Context, config *testConfig, svcInfo servicedeployer.ServiceInfo) ([]testrunner.TestResult, error) {
result := r.newResult(config.Name())

if config.Skip != nil {
if skip := testrunner.AnySkipConfig(config.Skip, r.globalTestConfig.Skip); skip != nil {
logger.Warnf("skipping %s test for %s/%s: %s (details: %s)",
TestType, r.testFolder.Package, r.testFolder.DataStream,
config.Skip.Reason, config.Skip.Link)
return result.WithSkip(config.Skip)
}

if r.globalConfig.Skip != nil {
logger.Warnf("skipping %s test for %s/%s: %s (details: %s)",
TestType, r.testFolder.Package, r.testFolder.DataStream,
r.globalConfig.Skip.Reason, r.globalConfig.Skip.Link.String())
return result.WithSkip(r.globalConfig.Skip)
skip.Reason, skip.Link)
return result.WithSkip(skip)
}

logger.Debugf("running test with configuration '%s'", config.Name())
Expand Down
9 changes: 9 additions & 0 deletions internal/testrunner/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,12 @@ func PackageHasDataStreams(manifest *packages.PackageManifest) (bool, error) {
return false, fmt.Errorf("unexpected package type %q", manifest.Type)
}
}

func AnySkipConfig(configs ...*SkipConfig) *SkipConfig {
for _, config := range configs {
if config != nil {
return config
}
}
return nil
}

0 comments on commit 5f04b26

Please sign in to comment.