aboutsummaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-12-03 12:53:33 +0100
committerJon Marius Venstad <venstad@gmail.com>2021-12-03 12:53:33 +0100
commitd7953c71c4d3ff5242484f00fa0fab84e9ae05b3 (patch)
tree35a6fa2ecf9871a34297eb1116a483d55d792dc5 /client
parent3825b93a34e921ba91ce46bc40a290cbcd85d7e5 (diff)
Colorise vespa-cli test output
Diffstat (limited to 'client')
-rw-r--r--client/go/cmd/test.go38
-rw-r--r--client/go/cmd/test_test.go2
-rw-r--r--client/go/cmd/testdata/tests/expected-suite.out2
-rw-r--r--client/go/cmd/testdata/tests/expected.out2
4 files changed, 29 insertions, 15 deletions
diff --git a/client/go/cmd/test.go b/client/go/cmd/test.go
index 4f01de823ea..7ba7a19b235 100644
--- a/client/go/cmd/test.go
+++ b/client/go/cmd/test.go
@@ -48,7 +48,11 @@ $ vespa test src/test/application/tests/system-test/feed-and-query.json`,
testPath = args[0]
}
if count, failed := runTests(testPath, target, false); len(failed) != 0 {
- fmt.Fprintf(stdout, "\nFailed %d of %d tests:\n", len(failed), count)
+ plural := "s"
+ if count == 1 {
+ plural = ""
+ }
+ fmt.Fprintf(stdout, "\n%s %d of %d test%s failed:\n", color.Red("Failure:"), len(failed), count, plural)
for _, test := range failed {
fmt.Fprintln(stdout, test)
}
@@ -58,7 +62,7 @@ $ vespa test src/test/application/tests/system-test/feed-and-query.json`,
if count == 1 {
plural = ""
}
- fmt.Fprintf(stdout, "\n%d test%s completed successfully\n", count, plural)
+ fmt.Fprintf(stdout, "\n%s %d test%s OK\n", color.Green("Success:"), count, plural)
}
},
}
@@ -118,7 +122,7 @@ func runTest(testPath string, target vespa.Target, dryRun bool) string {
testName = filepath.Base(testPath)
}
if !dryRun {
- fmt.Fprintf(stdout, "Running %s:", testName)
+ fmt.Fprintf(stdout, "Running %s:", color.Cyan(testName))
}
defaultParameters, err := getParameters(test.Defaults.ParametersRaw, path.Dir(testPath))
@@ -143,17 +147,17 @@ func runTest(testPath string, target vespa.Target, dryRun bool) string {
}
if !dryRun {
if failure != "" {
- fmt.Fprintf(stdout, " Failed %s:\n%s\n", stepName, longFailure)
+ fmt.Fprintf(stdout, " %s %s:\n%s\n", color.Red("Failed"), color.Cyan(stepName), longFailure)
return fmt.Sprintf("%s: %s: %s", testName, stepName, failure)
}
if i == 0 {
fmt.Fprintf(stdout, " ")
}
- fmt.Fprint(stdout, ".")
+ fmt.Fprint(stdout, color.Green("."))
}
}
if !dryRun {
- fmt.Fprintln(stdout, " OK")
+ fmt.Fprintln(stdout, color.Green(" OK"))
}
return ""
}
@@ -263,8 +267,8 @@ func verify(step step, testsPath string, defaultCluster string, defaultParameter
defer response.Body.Close()
if statusCode != response.StatusCode {
- failure := fmt.Sprintf("Unexpected status code: %d", response.StatusCode)
- return failure, fmt.Sprintf("%s\nExpected: %d\nActual response:\n%s", failure, statusCode, util.ReaderToJSON(response.Body)), nil
+ failure := fmt.Sprintf("Unexpected %s: %s", "status code", color.Red(response.StatusCode))
+ return failure, fmt.Sprintf("%s\nExpected: %s\nActual response:\n%s", failure, color.Cyan(statusCode), util.ReaderToJSON(response.Body)), nil
}
if responseBodySpec == nil {
@@ -326,7 +330,12 @@ func compare(expected interface{}, actual interface{}, path string) (string, str
}
valueMatch = true
} else {
- return fmt.Sprintf("Unexpected number of elements at %s: %d", path, len(v)), fmt.Sprintf("Expected: %d", len(u)), nil
+ return fmt.Sprintf("Unexpected %s at %s: %d",
+ "number of elements",
+ color.Cyan(path),
+ color.Red(len(v))),
+ fmt.Sprintf("Expected: %d", color.Cyan(len(u))),
+ nil
}
}
case map[string]interface{}:
@@ -337,7 +346,7 @@ func compare(expected interface{}, actual interface{}, path string) (string, str
childPath := fmt.Sprintf("%s/%s", path, strings.ReplaceAll(strings.ReplaceAll(n, "~", "~0"), "/", "~1"))
f, ok := v[n]
if !ok {
- return fmt.Sprintf("Missing expected field at %s", childPath), "", nil
+ return fmt.Sprintf("Missing expected field at %s", color.Red(childPath)), "", nil
}
failure, expected, err := compare(e, f, childPath)
if failure != "" || err != nil {
@@ -347,7 +356,7 @@ func compare(expected interface{}, actual interface{}, path string) (string, str
valueMatch = true
}
default:
- return "", "", fmt.Errorf("unexpected expected JSON type for value '%v'", expected)
+ return "", "", fmt.Errorf("unexpected JSON type for value '%v'", expected)
}
if !valueMatch {
@@ -360,7 +369,12 @@ func compare(expected interface{}, actual interface{}, path string) (string, str
}
expectedJson, _ := json.Marshal(expected)
actualJson, _ := json.Marshal(actual)
- return fmt.Sprintf("Unexpected %s at %s: %s", mismatched, path, actualJson), fmt.Sprintf("Expected: %s", expectedJson), nil
+ return fmt.Sprintf("Unexpected %s at %s: %s",
+ mismatched,
+ color.Cyan(path),
+ color.Red(actualJson)),
+ fmt.Sprintf("Expected: %s", color.Cyan(expectedJson)),
+ nil
}
return "", "", nil
}
diff --git a/client/go/cmd/test_test.go b/client/go/cmd/test_test.go
index 9a566beb10f..4c5e4c3f1e5 100644
--- a/client/go/cmd/test_test.go
+++ b/client/go/cmd/test_test.go
@@ -45,7 +45,7 @@ func TestProductionTest(t *testing.T) {
client := &mockHttpClient{}
client.NextStatus(200)
outBytes, errBytes := execute(command{args: []string{"test", "testdata/tests/production-test/external.json"}}, t, client)
- assert.Equal(t, "Running external.json: . OK\n\n1 test completed successfully\n", outBytes)
+ assert.Equal(t, "Running external.json: . OK\n\nSuccess: 1 test OK\n", outBytes)
assert.Equal(t, "", errBytes)
assertRequests([]*http.Request{createRequest("GET", "https://my.service:123/path?query=wohoo", "")}, client, t)
}
diff --git a/client/go/cmd/testdata/tests/expected-suite.out b/client/go/cmd/testdata/tests/expected-suite.out
index bef3d678957..963889b8019 100644
--- a/client/go/cmd/testdata/tests/expected-suite.out
+++ b/client/go/cmd/testdata/tests/expected-suite.out
@@ -309,7 +309,7 @@ Actual response:
}
}
-Failed 8 of 9 tests:
+Failure: 8 of 9 tests failed:
wrong-bool-value.json: step 1: Unexpected value at /root/coverage/full: true
wrong-element-count.json: step 1: Unexpected number of elements at /root/children: 1
wrong-field-name.json: step 1: Missing expected field at /root/fields/totalCountDracula
diff --git a/client/go/cmd/testdata/tests/expected.out b/client/go/cmd/testdata/tests/expected.out
index d144dbe2cfa..084fb10f72a 100644
--- a/client/go/cmd/testdata/tests/expected.out
+++ b/client/go/cmd/testdata/tests/expected.out
@@ -1,3 +1,3 @@
Running my test: .... OK
-1 test completed successfully
+Success: 1 test OK