Skip to content

Commit 08ea257

Browse files
authored
Do not create kibana client for pipeline and static tests (#1567)
This PR avoids creating the kibana client for the tests where it is not needed the access to Kibana (API). In this case, this is removed from pipeline and static tests.
1 parent 812292e commit 08ea257

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

cmd/testrunner.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/elastic/elastic-package/internal/cobraext"
1717
"github.com/elastic/elastic-package/internal/common"
1818
"github.com/elastic/elastic-package/internal/install"
19+
"github.com/elastic/elastic-package/internal/kibana"
1920
"github.com/elastic/elastic-package/internal/packages"
2021
"github.com/elastic/elastic-package/internal/signal"
2122
"github.com/elastic/elastic-package/internal/stack"
@@ -224,9 +225,13 @@ func testTypeCommandActionFactory(runner testrunner.TestRunner) cobraext.Command
224225
return err
225226
}
226227

227-
kibanaClient, err := stack.NewKibanaClientFromProfile(profile)
228-
if err != nil {
229-
return fmt.Errorf("can't create Kibana client: %w", err)
228+
var kibanaClient *kibana.Client
229+
if testType == "system" || testType == "asset" {
230+
// pipeline and static tests do not require a kibana client to perform their required operations
231+
kibanaClient, err = stack.NewKibanaClientFromProfile(profile)
232+
if err != nil {
233+
return fmt.Errorf("can't create Kibana client: %w", err)
234+
}
230235
}
231236

232237
var results []testrunner.TestResult

internal/testrunner/runners/asset/runner.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package asset
66

77
import (
8+
"errors"
89
"fmt"
910
"strings"
1011

@@ -64,6 +65,10 @@ func (r *runner) run() ([]testrunner.TestResult, error) {
6465
Package: r.testFolder.Package,
6566
})
6667

68+
if r.kibanaClient == nil {
69+
return result.WithError(errors.New("missing Kibana client"))
70+
}
71+
6772
testConfig, err := newConfig(r.testFolder.Path)
6873
if err != nil {
6974
return result.WithError(fmt.Errorf("unable to load asset loading test config file: %w", err))

internal/testrunner/runners/pipeline/runner.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (r *runner) run() ([]testrunner.TestResult, error) {
112112
return nil, fmt.Errorf("listing test case definitions failed: %w", err)
113113
}
114114

115+
if r.options.API == nil {
116+
return nil, errors.New("missing Elasticsearch client")
117+
}
118+
115119
dataStreamPath, found, err := packages.FindDataStreamRootForPath(r.options.TestFolder.Path)
116120
if err != nil {
117121
return nil, fmt.Errorf("locating data_stream root failed: %w", err)

internal/testrunner/runners/system/runner.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ func (r *runner) run() (results []testrunner.TestResult, err error) {
210210
logger.Debug("Running system tests for package")
211211
}
212212

213+
if r.options.API == nil {
214+
return result.WithError(errors.New("missing Elasticsearch client"))
215+
}
216+
if r.options.KibanaClient == nil {
217+
return result.WithError(errors.New("missing Kibana client"))
218+
}
219+
213220
stackVersion, err := r.options.KibanaClient.Version()
214221
if err != nil {
215222
return result.WithError(fmt.Errorf("cannot request Kibana version: %w", err))

0 commit comments

Comments
 (0)