@@ -25,7 +25,11 @@ import (
25
25
"github.com/elastic/elastic-package/internal/testrunner"
26
26
"github.com/elastic/elastic-package/internal/testrunner/reporters/formats"
27
27
"github.com/elastic/elastic-package/internal/testrunner/reporters/outputs"
28
- _ "github.com/elastic/elastic-package/internal/testrunner/runners" // register all test runners
28
+ "github.com/elastic/elastic-package/internal/testrunner/runners/asset"
29
+ "github.com/elastic/elastic-package/internal/testrunner/runners/pipeline"
30
+ "github.com/elastic/elastic-package/internal/testrunner/runners/policy"
31
+ "github.com/elastic/elastic-package/internal/testrunner/runners/static"
32
+ "github.com/elastic/elastic-package/internal/testrunner/runners/system"
29
33
)
30
34
31
35
const testLongDescription = `Use this command to run tests on a package. Currently, the following types of tests are available:
@@ -164,16 +168,13 @@ func testRunnerAssetCommandAction(cmd *cobra.Command, args []string) error {
164
168
165
169
_ , pkg := filepath .Split (packageRootPath )
166
170
167
- results , err := testrunner .Run (ctx , testType , testrunner.TestOptions {
168
- Profile : profile ,
169
- TestFolder : testrunner.TestFolder {Package : pkg },
170
- PackageRootPath : packageRootPath ,
171
- WithCoverage : testCoverage ,
172
- CoverageType : testCoverageFormat ,
173
- KibanaClient : kibanaClient ,
174
- RunIndependentElasticAgent : false ,
171
+ runner := asset .NewAssetRunner (asset.AssetRunnerOptions {
172
+ TestFolder : testrunner.TestFolder {Package : pkg },
173
+ PackageRootPath : packageRootPath ,
174
+ KibanaClient : kibanaClient ,
175
175
})
176
176
177
+ results , err := testrunner .Run (ctx , runner )
177
178
if err != nil {
178
179
return fmt .Errorf ("error running package %s tests: %w" , testType , err )
179
180
}
@@ -200,11 +201,6 @@ func testRunnerStaticCommandAction(cmd *cobra.Command, args []string) error {
200
201
cmd .Printf ("Run static tests for the package\n " )
201
202
testType := testrunner .TestType ("static" )
202
203
203
- profile , err := cobraext .GetProfileFlag (cmd )
204
- if err != nil {
205
- return err
206
- }
207
-
208
204
failOnMissing , err := cmd .Flags ().GetBool (cobraext .FailOnMissingFlagName )
209
205
if err != nil {
210
206
return cobraext .FlagParsingError (err , cobraext .FailOnMissingFlagName )
@@ -295,20 +291,15 @@ func testRunnerStaticCommandAction(cmd *cobra.Command, args []string) error {
295
291
296
292
var results []testrunner.TestResult
297
293
for _ , folder := range testFolders {
298
- r , err := testrunner .Run (ctx , testType , testrunner.TestOptions {
299
- Profile : profile ,
300
- TestFolder : folder ,
301
- PackageRootPath : packageRootPath ,
302
- RunIndependentElasticAgent : false ,
294
+ runner := static .NewStaticRunner (static.StaticRunnerOptions {
295
+ TestFolder : folder ,
296
+ PackageRootPath : packageRootPath ,
303
297
})
304
-
305
- // Results must be appended even if there is an error, since there could be
306
- // tests (e.g. system tests) that return both error and results.
307
- results = append (results , r ... )
308
-
298
+ r , err := testrunner .Run (ctx , runner )
309
299
if err != nil {
310
300
return fmt .Errorf ("error running package %s tests: %w" , testType , err )
311
301
}
302
+ results = append (results , r ... )
312
303
}
313
304
314
305
return processResults (results , testType , reportFormat , reportOutput , packageRootPath , manifest .Name , manifest .Type , testCoverageFormat , testCoverage )
@@ -449,25 +440,25 @@ func testRunnerPipelineCommandAction(cmd *cobra.Command, args []string) error {
449
440
450
441
var results []testrunner.TestResult
451
442
for _ , folder := range testFolders {
452
- r , err := testrunner .Run (ctx , testType , testrunner.TestOptions {
453
- Profile : profile ,
454
- TestFolder : folder ,
455
- PackageRootPath : packageRootPath ,
456
- GenerateTestResult : generateTestResult ,
457
- API : esClient .API ,
458
- WithCoverage : testCoverage ,
459
- CoverageType : testCoverageFormat ,
460
- DeferCleanup : deferCleanup ,
461
- RunIndependentElasticAgent : false ,
443
+ runner , err := pipeline .NewPipelineRunner (pipeline.PipelineRunnerOptions {
444
+ Profile : profile ,
445
+ TestFolder : folder ,
446
+ PackageRootPath : packageRootPath ,
447
+ GenerateTestResult : generateTestResult ,
448
+ API : esClient .API ,
449
+ WithCoverage : testCoverage ,
450
+ CoverageType : testCoverageFormat ,
451
+ DeferCleanup : deferCleanup ,
462
452
})
453
+ if err != nil {
454
+ return fmt .Errorf ("failed to create pipeline runner: %w" , err )
455
+ }
463
456
464
- // Results must be appended even if there is an error, since there could be
465
- // tests (e.g. system tests) that return both error and results.
466
- results = append (results , r ... )
467
-
457
+ r , err := testrunner .Run (ctx , runner )
468
458
if err != nil {
469
459
return fmt .Errorf ("error running package %s tests: %w" , testType , err )
470
460
}
461
+ results = append (results , r ... )
471
462
}
472
463
473
464
return processResults (results , testType , reportFormat , reportOutput , packageRootPath , manifest .Name , manifest .Type , testCoverageFormat , testCoverage )
@@ -691,7 +682,7 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
691
682
692
683
var results []testrunner.TestResult
693
684
for _ , folder := range testFolders {
694
- r , err := testrunner . Run ( ctx , testType , testrunner. TestOptions {
685
+ runner := system . NewSystemRunner (system. SystemRunnerOptions {
695
686
Profile : profile ,
696
687
TestFolder : folder ,
697
688
PackageRootPath : packageRootPath ,
@@ -707,13 +698,11 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
707
698
RunIndependentElasticAgent : false ,
708
699
})
709
700
710
- // Results must be appended even if there is an error, since there could be
711
- // tests (e.g. system tests) that return both error and results.
712
- results = append (results , r ... )
713
-
701
+ r , err := testrunner .Run (ctx , runner )
714
702
if err != nil {
715
703
return fmt .Errorf ("error running package %s tests: %w" , testType , err )
716
704
}
705
+ results = append (results , r ... )
717
706
}
718
707
719
708
return processResults (results , testType , reportFormat , reportOutput , packageRootPath , manifest .Name , manifest .Type , testCoverageFormat , testCoverage )
@@ -845,22 +834,17 @@ func testRunnerPolicyCommandAction(cmd *cobra.Command, args []string) error {
845
834
846
835
var results []testrunner.TestResult
847
836
for _ , folder := range testFolders {
848
- r , err := testrunner .Run (ctx , testType , testrunner.TestOptions {
849
- Profile : profile ,
850
- TestFolder : folder ,
851
- PackageRootPath : packageRootPath ,
852
- GenerateTestResult : generateTestResult ,
853
- KibanaClient : kibanaClient ,
854
- RunIndependentElasticAgent : false ,
837
+ runner := policy .NewPolicyRunner (policy.PolicyRunnerOptions {
838
+ TestFolder : folder ,
839
+ PackageRootPath : packageRootPath ,
840
+ GenerateTestResult : generateTestResult ,
841
+ KibanaClient : kibanaClient ,
855
842
})
856
-
857
- // Results must be appended even if there is an error, since there could be
858
- // tests (e.g. system tests) that return both error and results.
859
- results = append (results , r ... )
860
-
843
+ r , err := testrunner .Run (ctx , runner )
861
844
if err != nil {
862
845
return fmt .Errorf ("error running package %s tests: %w" , testType , err )
863
846
}
847
+ results = append (results , r ... )
864
848
}
865
849
866
850
return processResults (results , testType , reportFormat , reportOutput , packageRootPath , manifest .Name , manifest .Type , testCoverageFormat , testCoverage )
0 commit comments