aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/cli/cmd/test.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/internal/cli/cmd/test.go')
-rw-r--r--client/go/internal/cli/cmd/test.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/client/go/internal/cli/cmd/test.go b/client/go/internal/cli/cmd/test.go
index 3bc78fc91c8..5144abe95b4 100644
--- a/client/go/internal/cli/cmd/test.go
+++ b/client/go/internal/cli/cmd/test.go
@@ -42,7 +42,8 @@ $ vespa test src/test/application/tests/system-test/feed-and-query.json`,
DisableAutoGenTag: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
- count, failed, err := runTests(cli, args[0], false, waitSecs)
+ waiter := cli.waiter(time.Duration(waitSecs)*time.Second, cmd)
+ count, failed, err := runTests(cli, args[0], false, waiter)
if err != nil {
return err
}
@@ -70,7 +71,7 @@ $ vespa test src/test/application/tests/system-test/feed-and-query.json`,
return testCmd
}
-func runTests(cli *CLI, rootPath string, dryRun bool, waitSecs int) (int, []string, error) {
+func runTests(cli *CLI, rootPath string, dryRun bool, waiter *Waiter) (int, []string, error) {
count := 0
failed := make([]string, 0)
if stat, err := os.Stat(rootPath); err != nil {
@@ -89,7 +90,7 @@ func runTests(cli *CLI, rootPath string, dryRun bool, waitSecs int) (int, []stri
fmt.Fprintln(cli.Stdout, "")
previousFailed = false
}
- failure, err := runTest(testPath, context, waitSecs)
+ failure, err := runTest(testPath, context, waiter)
if err != nil {
return 0, nil, err
}
@@ -101,7 +102,7 @@ func runTests(cli *CLI, rootPath string, dryRun bool, waitSecs int) (int, []stri
}
}
} else if strings.HasSuffix(stat.Name(), ".json") {
- failure, err := runTest(rootPath, testContext{testsPath: filepath.Dir(rootPath), dryRun: dryRun, cli: cli, clusters: map[string]*vespa.Service{}}, waitSecs)
+ failure, err := runTest(rootPath, testContext{testsPath: filepath.Dir(rootPath), dryRun: dryRun, cli: cli, clusters: map[string]*vespa.Service{}}, waiter)
if err != nil {
return 0, nil, err
}
@@ -117,7 +118,7 @@ func runTests(cli *CLI, rootPath string, dryRun bool, waitSecs int) (int, []stri
}
// Runs the test at the given path, and returns the specified test name if the test fails
-func runTest(testPath string, context testContext, waitSecs int) (string, error) {
+func runTest(testPath string, context testContext, waiter *Waiter) (string, error) {
var test test
testBytes, err := os.ReadFile(testPath)
if err != nil {
@@ -150,7 +151,7 @@ func runTest(testPath string, context testContext, waitSecs int) (string, error)
if step.Name != "" {
stepName += ": " + step.Name
}
- failure, longFailure, err := verify(step, test.Defaults.Cluster, defaultParameters, context, waitSecs)
+ failure, longFailure, err := verify(step, test.Defaults.Cluster, defaultParameters, context, waiter)
if err != nil {
fmt.Fprintln(context.cli.Stderr)
return "", errHint(fmt.Errorf("error in %s: %w", stepName, err), "See https://docs.vespa.ai/en/reference/testing")
@@ -173,7 +174,7 @@ func runTest(testPath string, context testContext, waitSecs int) (string, error)
}
// Asserts specified response is obtained for request, or returns a failure message, or an error if this fails
-func verify(step step, defaultCluster string, defaultParameters map[string]string, context testContext, waitSecs int) (string, string, error) {
+func verify(step step, defaultCluster string, defaultParameters map[string]string, context testContext, waiter *Waiter) (string, string, error) {
requestBody, err := getBody(step.Request.BodyRaw, context.testsPath)
if err != nil {
return "", "", err
@@ -227,9 +228,8 @@ func verify(step step, defaultCluster string, defaultParameters map[string]strin
}
ok := false
service, ok = context.clusters[cluster]
- if !ok {
+ if !ok && waiter != nil {
// Cache service so we don't have to discover it for every step
- waiter := context.cli.waiter(time.Duration(waitSecs) * time.Second)
service, err = waiter.Service(target, cluster)
if err != nil {
return "", "", err