Skip to content

Commit 09feb99

Browse files
feat: singleTest mage target for each integration test package (#8691) (#8789)
* feat: support running a single test for serverless and resource leak integration tests * doc: update test-framework-dev-guide.md to include the latest mage targets (cherry picked from commit 2ec9992) Co-authored-by: Panos Koutsovasilis <panos.koutsovasilis@elastic.co>
1 parent 3758211 commit 09feb99

File tree

2 files changed

+61
-31
lines changed

2 files changed

+61
-31
lines changed

docs/test-framework-dev-guide.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,41 @@ Go to https://docker-auth.elastic.co/ and authenticate with Okta to receive your
6464

6565
The test are run with mage using the `integration` namespace:
6666

67-
- `mage integration:test` to execute all tests under the `testing/integration`
67+
#### ESS oriented tests
68+
69+
- `mage integration:test` to execute all tests under the `testing/integration/ess`
6870
folder. All tests are executed on remote VMs, including those that set `Local: true`.
6971

7072
- `mage integration:local [testName|all]` to execute only those tests under the
71-
`testing/integration` folder that set `Local: true`. It'll run all the tests if
73+
`testing/integration/ess` folder that set `Local: true`. It'll run all the tests if
7274
`all` is passed as argument, or it'll pass `[testName]` to `go test` as
7375
`--run=[testName]`. These tests are executed on your local machine.
7476

75-
- `mage integration:single [testName]` to execute a single test under the `testing/integration` folder. Only the selected test will be executed on remote VMs.
77+
- `mage integration:single [testName]` to execute a single test under the `testing/integration/ess` folder. Only the selected test will be executed on remote VMs.
78+
79+
- `mage integration:matrix` to run all tests under the `testing/integration/ess` folder on the complete matrix of supported operating systems and architectures of the Elastic Agent.
80+
81+
#### Kubernetes oriented tests
82+
83+
- `mage integration:testKubernetes` to run kubernetes tests under the `testing/integration/k8s` folder for the default image on the default version of kubernetes (all previous commands will not run any kubernetes tests).
84+
85+
- `mage integration:testKubernetesMatrix` to run a matrix of kubernetes tests under the `testing/integration/k8s` folder for all image types and supported versions of kubernetes.
86+
87+
- `mage integration:testKubernetesSingle [testName|all]` to execute a single test under the `testing/integration/k8s` folder. Only the selected test will be executed.
88+
89+
#### Serverless oriented tests
90+
91+
- `mage integration:testServerless` to execute all tests under the `testing/integration/serverless` folder. All tests are executed on remote VMs, including those that set `Local: true`.
92+
93+
- `mage integration:testServerlessSingle [testName|all]` to execute a single test under the `testing/integration/serverless` folder. Only the selected test will be executed on remote VMs.
94+
95+
#### Resource leaks tests
7696

77-
- `mage integration:matrix` to run all tests on the complete matrix of supported operating systems and architectures of the Elastic Agent.
97+
- `mage integration:testForResourceLeaks` to execute all tests under the `testing/integration/leak` folder. All tests are executed on remote VMs.
7898

79-
- `mage integration:testKubernetes` to run kubernetes tests for the default image on the default version of kubernetes (all previous commands will not run any kubernetes tests).
99+
- `mage integration:testForResourceLeaksSingle [testName|all]` to execute a single test under the `testing/integration/leak` folder. Only the selected test will be executed on remote VMs.
80100

81-
- `mage integration:testKubernetesMatrix` to run a matrix of kubernetes tests for all image types and supported versions of kubernetes.
101+
You can list all available mage targets by running `mage -l`
82102

83103
#### Selecting specific platform
84104

magefile.go

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,46 +2320,47 @@ func (Integration) Single(ctx context.Context, testName string) error {
23202320
}
23212321

23222322
// TestServerless runs the integration tests defined in testing/integration/serverless
2323-
func (Integration) TestServerless(ctx context.Context) error {
2323+
func (i Integration) TestServerless(ctx context.Context) error {
2324+
return i.testServerless(ctx, false, "")
2325+
}
2326+
2327+
// TestServerlessSingle runs a single integration test defined in testing/integration/serverless
2328+
func (i Integration) TestServerlessSingle(ctx context.Context, testName string) error {
2329+
return i.testServerless(ctx, false, testName)
2330+
}
2331+
2332+
func (i Integration) testServerless(ctx context.Context, matrix bool, testName string) error {
23242333
err := os.Setenv("STACK_PROVISIONER", "serverless")
23252334
if err != nil {
23262335
return fmt.Errorf("error setting serverless stack env var: %w", err)
23272336
}
23282337

2329-
return integRunner(ctx, "testing/integration/serverless", false, "")
2338+
return integRunner(ctx, "testing/integration/serverless", matrix, testName)
23302339
}
23312340

2332-
// TestKubernetes runs kubernetes integration tests
2333-
func (Integration) TestKubernetes(ctx context.Context) error {
2334-
mg.Deps(Integration.BuildKubernetesTestData)
2335-
// invoke integration tests
2336-
if err := os.Setenv("TEST_GROUPS", "kubernetes"); err != nil {
2337-
return err
2338-
}
2339-
2340-
return integRunner(ctx, "testing/integration/k8s", false, "")
2341+
// TestKubernetes runs the integration tests defined in testing/integration/k8s
2342+
func (i Integration) TestKubernetes(ctx context.Context) error {
2343+
return i.testKubernetes(ctx, false, "")
23412344
}
23422345

2343-
// TestKubernetesSingle runs single k8s integration test
2344-
func (Integration) TestKubernetesSingle(ctx context.Context, testName string) error {
2345-
mg.Deps(Integration.BuildKubernetesTestData)
2346-
// invoke integration tests
2347-
if err := os.Setenv("TEST_GROUPS", "kubernetes"); err != nil {
2348-
return err
2349-
}
2346+
// TestKubernetesSingle runs a single integration test defined in testing/integration/k8s
2347+
func (i Integration) TestKubernetesSingle(ctx context.Context, testName string) error {
2348+
return i.testKubernetes(ctx, false, testName)
2349+
}
23502350

2351-
return integRunner(ctx, "testing/integration/k8s", false, testName)
2351+
// TestKubernetesMatrix runs a matrix of integration tests defined in testing/integration/k8s
2352+
func (i Integration) TestKubernetesMatrix(ctx context.Context) error {
2353+
return i.testKubernetes(ctx, true, "")
23522354
}
23532355

2354-
// TestKubernetesMatrix runs a matrix of kubernetes integration tests
2355-
func (Integration) TestKubernetesMatrix(ctx context.Context) error {
2356+
func (i Integration) testKubernetes(ctx context.Context, matrix bool, testName string) error {
23562357
mg.Deps(Integration.BuildKubernetesTestData)
23572358
// invoke integration tests
23582359
if err := os.Setenv("TEST_GROUPS", "kubernetes"); err != nil {
23592360
return err
23602361
}
23612362

2362-
return integRunner(ctx, "testing/integration/k8s", true, "")
2363+
return integRunner(ctx, "testing/integration/k8s", matrix, testName)
23632364
}
23642365

23652366
// BuildKubernetesTestData builds the test data required to run k8s integration tests
@@ -2896,9 +2897,18 @@ func (Integration) TestBeatServerless(ctx context.Context, beatname string) erro
28962897
return integRunner(ctx, "testing/integration/beats/serverless", false, "TestBeatsServerless")
28972898
}
28982899

2899-
// TestForResourceLeaks runs tests that check for resource leaks
2900-
func (Integration) TestForResourceLeaks(ctx context.Context) error {
2901-
return integRunner(ctx, "testing/integration/leak", false, "TestLongRunningAgentForLeaks")
2900+
// TestForResourceLeaks runs the integration tests defined in testing/integration/leak
2901+
func (i Integration) TestForResourceLeaks(ctx context.Context) error {
2902+
return i.testForResourceLeaks(ctx, false, "")
2903+
}
2904+
2905+
// TestForResourceLeaksSingle runs a single integration test defined in testing/integration/leak
2906+
func (i Integration) TestForResourceLeaksSingle(ctx context.Context, testName string) error {
2907+
return i.testForResourceLeaks(ctx, false, testName)
2908+
}
2909+
2910+
func (i Integration) testForResourceLeaks(ctx context.Context, matrix bool, testName string) error {
2911+
return integRunner(ctx, "testing/integration/leak", matrix, testName)
29022912
}
29032913

29042914
// TestOnRemote shouldn't be called locally (called on remote host to perform testing)

0 commit comments

Comments
 (0)