Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ func getTestRunnerSystemCommand() *cobra.Command {
cmd.Flags().Bool(cobraext.TearDownFlagName, false, cobraext.TearDownFlagDescription)
cmd.Flags().Bool(cobraext.NoProvisionFlagName, false, cobraext.NoProvisionFlagDescription)

cmd.Flags().String(cobraext.TestDumpPrefixFlagName, "", cobraext.TestDumpPrefixFlagDescription)

cmd.MarkFlagsMutuallyExclusive(cobraext.SetupFlagName, cobraext.TearDownFlagName, cobraext.NoProvisionFlagName)
cmd.MarkFlagsRequiredTogether(cobraext.ConfigFileFlagName, cobraext.SetupFlagName)

Expand Down Expand Up @@ -472,6 +474,11 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
return cobraext.FlagParsingError(err, cobraext.TestCoverageFormatFlagName)
}

dumpPrefix, err := cmd.Flags().GetString(cobraext.TestDumpPrefixFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.TestDumpPrefixFlagName)
}

if !slices.Contains(testrunner.CoverageFormatsList(), testCoverageFormat) {
return cobraext.FlagParsingError(fmt.Errorf("coverage format not available: %s", testCoverageFormat), cobraext.TestCoverageFormatFlagName)
}
Expand Down Expand Up @@ -578,6 +585,7 @@ func testRunnerSystemCommandAction(cmd *cobra.Command, args []string) error {
GlobalTestConfig: globalTestConfig.System,
WithCoverage: testCoverage,
CoverageType: testCoverageFormat,
DumpPrefix: dumpPrefix,
})

logger.Debugf("Running suite...")
Expand Down
3 changes: 3 additions & 0 deletions internal/cobraext/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ const (
TestCoverageFormatFlagName = "coverage-format"
TestCoverageFormatFlagDescription = "set format for coverage reports: %s"

TestDumpPrefixFlagName = "dump-docs"
TestDumpPrefixFlagDescription = "prefix for system test document output dump file"

VariantFlagName = "variant"
VariantFlagDescription = "service variant"

Expand Down
4 changes: 4 additions & 0 deletions internal/testrunner/runners/system/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type runner struct {
generateTestResult bool
withCoverage bool
coverageType string
dumpPrefix string

configFilePath string
runSetup bool
Expand Down Expand Up @@ -76,6 +77,7 @@ type SystemTestRunnerOptions struct {
DeferCleanup time.Duration
WithCoverage bool
CoverageType string
DumpPrefix string
}

func NewSystemTestRunner(options SystemTestRunnerOptions) *runner {
Expand All @@ -97,6 +99,7 @@ func NewSystemTestRunner(options SystemTestRunnerOptions) *runner {
globalTestConfig: options.GlobalTestConfig,
withCoverage: options.WithCoverage,
coverageType: options.CoverageType,
dumpPrefix: options.DumpPrefix,
}

r.resourcesManager = resources.NewManager()
Expand Down Expand Up @@ -262,6 +265,7 @@ func (r *runner) GetTests(ctx context.Context) ([]testrunner.Tester, error) {
GlobalTestConfig: r.globalTestConfig,
WithCoverage: r.withCoverage,
CoverageType: r.coverageType,
DumpPrefix: r.dumpPrefix,
})
if err != nil {
return nil, fmt.Errorf(
Expand Down
50 changes: 29 additions & 21 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ type tester struct {
dataStreamManifest *packages.DataStreamManifest
withCoverage bool
coverageType string
dumpPrefix string

serviceStateFilePath string

Expand Down Expand Up @@ -218,6 +219,7 @@ type SystemTesterOptions struct {
GlobalTestConfig testrunner.GlobalRunnerTestConfig
WithCoverage bool
CoverageType string
DumpPrefix string

RunSetup bool
RunTearDown bool
Expand Down Expand Up @@ -672,7 +674,6 @@ func (r *tester) runTestPerVariant(ctx context.Context, stackConfig stack.Config
logger.Debugf("Using config: %q", testConfig.Name())

partial, err := r.runTest(ctx, testConfig, stackConfig, svcInfo)

tdErr := r.tearDownTest(ctx)
if err != nil {
return partial, err
Expand Down Expand Up @@ -1814,32 +1815,26 @@ func (r *tester) runTest(ctx context.Context, config *testConfig, stackConfig st
return results, nil
}

if dump, ok := os.LookupEnv(dumpScenarioDocsEnv); ok && dump != "" {
err := dumpScenarioDocs(scenario.docs)
var dumpPath string
switch {
case r.dumpPrefix != "":
dumpPath = fmt.Sprintf("%s-%s.json", r.dumpPrefix, time.Now().Format("20060102150405"))
case os.Getenv(dumpScenarioDocsEnv) != "":
dumpPath = filepath.Join(os.TempDir(), fmt.Sprintf("elastic-package-test-docs-dump-%s.json", time.Now().Format("20060102150405")))
}
var dumpErr error
if dumpPath != "" {
err := dumpScenarioDocs(scenario.docs, dumpPath)
if err != nil {
return nil, fmt.Errorf("failed to dump scenario docs: %w", err)
dumpErr = fmt.Errorf("failed to dump scenario docs: %w", err)
}
}

return r.validateTestScenario(ctx, result, scenario, config)
}

func (r *tester) isTestUsingOTELCollectorInput(policyTemplateInput string) bool {
// Just supported for input packages currently
if r.pkgManifest.Type != "input" {
return false
}

if policyTemplateInput != otelCollectorInputName {
return false
}

return true
results, err := r.validateTestScenario(ctx, result, scenario, config)
return results, errors.Join(err, dumpErr)
}

func dumpScenarioDocs(docs any) error {
timestamp := time.Now().Format("20060102150405")
path := filepath.Join(os.TempDir(), fmt.Sprintf("elastic-package-test-docs-dump-%s.json", timestamp))
func dumpScenarioDocs(docs any, path string) error {
f, err := os.Create(path)
if err != nil {
return fmt.Errorf("failed to create dump file: %w", err)
Expand All @@ -1857,6 +1852,19 @@ func dumpScenarioDocs(docs any) error {
return nil
}

func (r *tester) isTestUsingOTELCollectorInput(policyTemplateInput string) bool {
// Just supported for input packages currently
if r.pkgManifest.Type != "input" {
return false
}

if policyTemplateInput != otelCollectorInputName {
return false
}

return true
}

func (r *tester) checkEnrolledAgents(ctx context.Context, agentInfo agentdeployer.AgentInfo, svcInfo servicedeployer.ServiceInfo) (*kibana.Agent, error) {
var agents []kibana.Agent

Expand Down