Skip to content

Commit

Permalink
add TEST_PACKAGES environment variable for integration tests (#4480)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ authored Mar 27, 2024
1 parent c082acc commit 6e4b379
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
18 changes: 18 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,7 @@ func createTestRunner(matrix bool, singleTest string, goTestFlags string, batche
DiagnosticsDir: diagDir,
StateDir: ".integration-cache",
Platforms: testPlatforms(),
Packages: testPackages(),
Groups: testGroups(),
Matrix: matrix,
SingleTest: singleTest,
Expand Down Expand Up @@ -2380,6 +2381,23 @@ func testPlatforms() []string {
return platforms
}

func testPackages() []string {
packagesStr, defined := os.LookupEnv("TEST_PACKAGES")
if !defined {
return nil
}

var packages []string
for _, p := range strings.Split(packagesStr, ",") {
if p == "tar.gz" {
p = "targz"
}
packages = append(packages, p)
}

return packages
}

func testGroups() []string {
groupsStr := os.Getenv("TEST_GROUPS")
if groupsStr == "" {
Expand Down
5 changes: 5 additions & 0 deletions pkg/testing/runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ type Config struct {
// defined in this list.
Platforms []string

// Packages filters the tests to only run on the provided list
// of platforms even if the tests supports more than what is
// defined in this list.
Packages []string

// BinaryName is the name of the binary package under test, i.e, elastic-agent, metricbeat, etc
// this is used to copy the .tar.gz to the remote host
BinaryName string
Expand Down
22 changes: 19 additions & 3 deletions pkg/testing/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,36 @@ func (r *Runner) validate() error {

// getBuilds returns the build for the batch.
func (r *Runner) getBuilds(b OSBatch) []Build {
builds := []Build{}
var builds []Build
formats := []string{"targz", "zip", "rpm", "deb"}
binaryName := "elastic-agent"

var packages []string
for _, p := range r.cfg.Packages {
if slices.Contains(formats, p) {
packages = append(packages, p)
}
}
if len(packages) == 0 {
packages = formats
}

// This is for testing beats in serverless environment
if strings.HasSuffix(r.cfg.BinaryName, "beat") {
formats = []string{"targz", "zip"}
var serverlessPackages []string
for _, p := range packages {
if slices.Contains([]string{"targz", "zip"}, p) {
packages = append(packages, p)
}
}
packages = serverlessPackages
}

if r.cfg.BinaryName != "" {
binaryName = r.cfg.BinaryName
}

for _, f := range formats {
for _, f := range packages {
arch := b.OS.Arch
if arch == define.AMD64 {
arch = "x86_64"
Expand Down

0 comments on commit 6e4b379

Please sign in to comment.