-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…6398) * add filtering integration tests by group * add dry-run integration test flag * mage check for define.Require should skip TestMain * Add define filter on sudo requirements (cherry picked from commit 7978189) Co-authored-by: Paolo Chilà <[email protected]>
- Loading branch information
1 parent
9f6ef22
commit 650adcf
Showing
4 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
package define | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
type optionalBoolFlag struct { | ||
value *bool | ||
} | ||
|
||
func (o *optionalBoolFlag) String() string { | ||
if o.value == nil { | ||
return "nil" | ||
} | ||
return strconv.FormatBool(*o.value) | ||
} | ||
|
||
func (o *optionalBoolFlag) Set(s string) error { | ||
bValue := s == "" || s == "true" | ||
o.value = &bValue | ||
return nil | ||
} | ||
|
||
type stringArrayFlag struct { | ||
values []string | ||
} | ||
|
||
func (s *stringArrayFlag) String() string { | ||
return fmt.Sprintf("%s", s.values) | ||
} | ||
|
||
func (s *stringArrayFlag) Set(stringValue string) error { | ||
if stringValue == "" { | ||
return nil | ||
} | ||
s.values = strings.Split(stringValue, ",") | ||
return nil | ||
} | ||
|
||
var ( | ||
DryRun bool | ||
GroupsFilter stringArrayFlag | ||
PlatformsFilter stringArrayFlag | ||
SudoFilter optionalBoolFlag | ||
) | ||
|
||
func RegisterFlags(prefix string, set *flag.FlagSet) { | ||
set.BoolVar(&DryRun, prefix+"dry-run", false, "Forces test in dry-run mode: skips the main test and puts a successful placeholder <TestName>/dry-run if the test would have run") | ||
set.Var(&GroupsFilter, prefix+"groups", "test groups, comma-separated") | ||
set.Var(&PlatformsFilter, prefix+"platforms", "test platforms, comma-separated") | ||
set.Var(&SudoFilter, prefix+"sudo", "Filter tests by sudo requirements") | ||
} | ||
|
||
func dryRun(t *testing.T, req Requirements) *Info { | ||
// always validate requirement is valid | ||
if err := req.Validate(); err != nil { | ||
t.Logf("test %s has invalid requirements: %s", t.Name(), err) | ||
t.FailNow() | ||
return nil | ||
} | ||
// skip the test as we are in dry run | ||
t.Run("dry-run", func(t *testing.T) { | ||
t.Log("Test dry-run successful") | ||
}) | ||
t.Skip("Skipped because dry-run mode has been specified.") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
package integration | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/elastic/elastic-agent/pkg/testing/define" | ||
) | ||
|
||
var flagSet = flag.CommandLine | ||
|
||
func init() { | ||
define.RegisterFlags("integration.", flagSet) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
runExitCode := m.Run() | ||
|
||
if define.DryRun { | ||
// TODO add parsing of requirements and dump them | ||
log.Print("Dry-run mode specified...") | ||
} | ||
|
||
os.Exit(runExitCode) | ||
} |