diff options
author | Martin Polden <mpolden@mpolden.no> | 2021-08-25 16:41:47 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2021-08-25 18:56:04 +0200 |
commit | 8b17d1006138b964317cdc7f8fb52f255bfe500c (patch) | |
tree | 879351df186d7e2b614a3d1a64ac30c6037bf64d /client | |
parent | 240fb94f82b8a59e70135deee6bc870e8ced2673 (diff) |
Avoid colorization of unrelated output
Diffstat (limited to 'client')
-rw-r--r-- | client/go/cmd/deploy_test.go | 21 | ||||
-rw-r--r-- | client/go/cmd/document_test.go | 13 | ||||
-rw-r--r-- | client/go/cmd/init_test.go | 7 | ||||
-rw-r--r-- | client/go/cmd/query_test.go | 7 | ||||
-rw-r--r-- | client/go/cmd/status_test.go | 13 | ||||
-rw-r--r-- | client/go/util/print.go | 7 |
6 files changed, 40 insertions, 28 deletions
diff --git a/client/go/cmd/deploy_test.go b/client/go/cmd/deploy_test.go index 45fbe95a094..9042bc2c2a8 100644 --- a/client/go/cmd/deploy_test.go +++ b/client/go/cmd/deploy_test.go @@ -5,15 +5,16 @@ package cmd import ( - "github.com/stretchr/testify/assert" "strconv" "testing" + + "github.com/stretchr/testify/assert" ) func TestDeployZip(t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mSuccess\n", + "\x1b[32mSuccess\x1b[0m\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withTarget/target/application.zip"}, []string{})) assertDeployRequestMade("http://127.0.0.1:19071", client, t) } @@ -21,7 +22,7 @@ func TestDeployZip(t *testing.T) { func TestDeployZipWithURLTargetArgument(t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mSuccess\n", + "\x1b[32mSuccess\x1b[0m\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withTarget/target/application.zip", "-t", "http://target:19071"}, []string{})) assertDeployRequestMade("http://target:19071", client, t) } @@ -29,7 +30,7 @@ func TestDeployZipWithURLTargetArgument(t *testing.T) { func TestDeployZipWitLocalTargetArgument(t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mSuccess\n", + "\x1b[32mSuccess\x1b[0m\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withTarget/target/application.zip", "-t", "local"}, []string{})) assertDeployRequestMade("http://127.0.0.1:19071", client, t) } @@ -37,7 +38,7 @@ func TestDeployZipWitLocalTargetArgument(t *testing.T) { func TestDeploySourceDirectory(t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mSuccess\n", + "\x1b[32mSuccess\x1b[0m\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withSource/src/main/application"}, []string{})) assertDeployRequestMade("http://127.0.0.1:19071", client, t) } @@ -45,7 +46,7 @@ func TestDeploySourceDirectory(t *testing.T) { func TestDeployApplicationDirectoryWithSource(t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mSuccess\n", + "\x1b[32mSuccess\x1b[0m\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withSource"}, []string{})) assertDeployRequestMade("http://127.0.0.1:19071", client, t) } @@ -53,7 +54,7 @@ func TestDeployApplicationDirectoryWithSource(t *testing.T) { func TestDeployApplicationDirectoryWithTarget(t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mSuccess\n", + "\x1b[32mSuccess\x1b[0m\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withTarget"}, []string{})) assertDeployRequestMade("http://127.0.0.1:19071", client, t) } @@ -61,7 +62,7 @@ func TestDeployApplicationDirectoryWithTarget(t *testing.T) { func TestDeployApplicationDirectoryWithEmptyTarget(t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[31mtarget/ exists but have no application.zip. Run mvn package first\n", + "\x1b[31mno application package found in testdata/applications/withEmptyTarget\x1b[0m\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withEmptyTarget"}, []string{})) } @@ -89,13 +90,13 @@ func assertDeployRequestMade(target string, client *mockHttpClient, t *testing.T func assertApplicationPackageError(t *testing.T, status int, errorMessage string) { client := &mockHttpClient{nextStatus: status, nextBody: errorMessage} assert.Equal(t, - "\x1b[31mInvalid application package (Status "+strconv.Itoa(status)+"):\n"+errorMessage+"\n", + "\x1b[31mInvalid application package (Status "+strconv.Itoa(status)+"):\x1b[0m\n"+errorMessage+"\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withTarget/target/application.zip"}, []string{})) } func assertDeployServerError(t *testing.T, status int, errorMessage string) { client := &mockHttpClient{nextStatus: status, nextBody: errorMessage} assert.Equal(t, - "\x1b[31mError from deploy service at 127.0.0.1:19071 (Status "+strconv.Itoa(status)+"):\n"+errorMessage+"\n", + "\x1b[31mError from deploy service at 127.0.0.1:19071 (Status "+strconv.Itoa(status)+"):\x1b[0m\n"+errorMessage+"\n", executeCommand(t, client, []string{"deploy", "testdata/applications/withTarget/target/application.zip"}, []string{})) } diff --git a/client/go/cmd/document_test.go b/client/go/cmd/document_test.go index 9d37e29c661..9f3bedc12e9 100644 --- a/client/go/cmd/document_test.go +++ b/client/go/cmd/document_test.go @@ -5,11 +5,12 @@ package cmd import ( - "github.com/stretchr/testify/assert" - "github.com/vespa-engine/vespa/util" "io/ioutil" "strconv" "testing" + + "github.com/stretchr/testify/assert" + "github.com/vespa-engine/vespa/util" ) func TestDocumentPostWithIdArg(t *testing.T) { @@ -36,7 +37,7 @@ func TestDocumentIdNotSpecified(t *testing.T) { arguments := []string{"document", "post", "testdata/A-Head-Full-of-Dreams.json"} client := &mockHttpClient{} assert.Equal(t, - "\x1b[31mNo document id given neither as argument or an 'id' key in the json file\n", + "\x1b[31mNo document id given neither as argument or an 'id' key in the json file\x1b[0m\n", executeCommand(t, client, arguments, []string{})) } @@ -51,7 +52,7 @@ func TestDocumentPostServerError(t *testing.T) { func assertDocumentPost(arguments []string, documentId string, jsonFile string, t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mSuccess\n", + "\x1b[32mSuccess\x1b[0m\n", executeCommand(t, client, arguments, []string{})) target := getTarget(documentContext).document assert.Equal(t, target+"/document/v1/"+documentId, client.lastRequest.URL.String()) @@ -74,7 +75,7 @@ func assertDocumentPostShortForm(documentId string, jsonFile string, t *testing. func assertDocumentError(t *testing.T, status int, errorMessage string) { client := &mockHttpClient{nextStatus: status, nextBody: errorMessage} assert.Equal(t, - "\x1b[31mInvalid document (Status "+strconv.Itoa(status)+"):\n"+errorMessage+"\n", + "\x1b[31mInvalid document (Status "+strconv.Itoa(status)+"):\x1b[0m\n"+errorMessage+"\n", executeCommand(t, client, []string{"document", "post", "mynamespace/music/docid/1", "testdata/A-Head-Full-of-Dreams.json"}, []string{})) @@ -83,7 +84,7 @@ func assertDocumentError(t *testing.T, status int, errorMessage string) { func assertDocumentServerError(t *testing.T, status int, errorMessage string) { client := &mockHttpClient{nextStatus: status, nextBody: errorMessage} assert.Equal(t, - "\x1b[31mError from container (document api) at 127.0.0.1:8080 (Status "+strconv.Itoa(status)+"):\n"+errorMessage+"\n", + "\x1b[31mError from container (document api) at 127.0.0.1:8080 (Status "+strconv.Itoa(status)+"):\x1b[0m\n"+errorMessage+"\n", executeCommand(t, client, []string{"document", "post", "mynamespace/music/docid/1", "testdata/A-Head-Full-of-Dreams.json"}, []string{})) diff --git a/client/go/cmd/init_test.go b/client/go/cmd/init_test.go index f93af26b2eb..d855acb08f3 100644 --- a/client/go/cmd/init_test.go +++ b/client/go/cmd/init_test.go @@ -5,11 +5,12 @@ package cmd import ( - "github.com/stretchr/testify/assert" - "github.com/vespa-engine/vespa/util" "os" "path/filepath" "testing" + + "github.com/stretchr/testify/assert" + "github.com/vespa-engine/vespa/util" ) func TestInit(t *testing.T) { @@ -20,7 +21,7 @@ func assertCreated(app string, sampleAppName string, t *testing.T) { existingSampleAppsZip = "testdata/sample-apps-master.zip" standardOut := executeCommand(t, &mockHttpClient{}, []string{"init", app, sampleAppName}, []string{}) defer os.RemoveAll(app) - assert.Equal(t, "\x1b[32mCreated "+app+"\n", standardOut) + assert.Equal(t, "\x1b[32mCreated "+app+"\x1b[0m\n", standardOut) assert.True(t, util.PathExists(filepath.Join(app, "README.md"))) assert.True(t, util.PathExists(filepath.Join(app, "src", "main", "application"))) assert.True(t, util.IsDirectory(filepath.Join(app, "src", "main", "application"))) diff --git a/client/go/cmd/query_test.go b/client/go/cmd/query_test.go index bf6cc13fe8a..5524c95ec0b 100644 --- a/client/go/cmd/query_test.go +++ b/client/go/cmd/query_test.go @@ -5,9 +5,10 @@ package cmd import ( - "github.com/stretchr/testify/assert" "strconv" "testing" + + "github.com/stretchr/testify/assert" ) func TestQuery(t *testing.T) { @@ -63,7 +64,7 @@ func assertQueryNonJsonResult(t *testing.T, expectedQuery string, query ...strin func assertQueryError(t *testing.T, status int, errorMessage string) { client := &mockHttpClient{nextStatus: status, nextBody: errorMessage} assert.Equal(t, - "\x1b[31mInvalid query (Status "+strconv.Itoa(status)+"):\n"+errorMessage+"\n", + "\x1b[31mInvalid query (Status "+strconv.Itoa(status)+"):\x1b[0m\n"+errorMessage+"\n", executeCommand(t, client, []string{"query"}, []string{"yql=select from sources * where title contains 'foo'"}), "error output") } @@ -71,7 +72,7 @@ func assertQueryError(t *testing.T, status int, errorMessage string) { func assertQueryServiceError(t *testing.T, status int, errorMessage string) { client := &mockHttpClient{nextStatus: status, nextBody: errorMessage} assert.Equal(t, - "\x1b[31mError from container at 127.0.0.1:8080 (Status "+strconv.Itoa(status)+"):\n"+errorMessage+"\n", + "\x1b[31mError from container at 127.0.0.1:8080 (Status "+strconv.Itoa(status)+"):\x1b[0m\n"+errorMessage+"\n", executeCommand(t, client, []string{"query"}, []string{"yql=select from sources * where title contains 'foo'"}), "error output") } diff --git a/client/go/cmd/status_test.go b/client/go/cmd/status_test.go index 19bfd2d756b..9fb9091b0bf 100644 --- a/client/go/cmd/status_test.go +++ b/client/go/cmd/status_test.go @@ -5,8 +5,9 @@ package cmd import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestStatusDeployCommand(t *testing.T) { @@ -44,7 +45,7 @@ func TestStatusErrorResponse(t *testing.T) { func assertDeployStatus(target string, args []string, t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mDeploy API at "+target+" is ready\n", + "\x1b[32mDeploy API at "+target+" is ready\x1b[0m\n", executeCommand(t, client, []string{"status", "deploy"}, args), "vespa status config-server") assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String()) @@ -53,13 +54,13 @@ func assertDeployStatus(target string, args []string, t *testing.T) { func assertQueryStatus(target string, args []string, t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mQuery API at "+target+" is ready\n", + "\x1b[32mQuery API at "+target+" is ready\x1b[0m\n", executeCommand(t, client, []string{"status", "query"}, args), "vespa status container") assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String()) assert.Equal(t, - "\x1b[32mQuery API at "+target+" is ready\n", + "\x1b[32mQuery API at "+target+" is ready\x1b[0m\n", executeCommand(t, client, []string{"status"}, args), "vespa status (the default)") assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String()) @@ -68,7 +69,7 @@ func assertQueryStatus(target string, args []string, t *testing.T) { func assertDocumentStatus(target string, args []string, t *testing.T) { client := &mockHttpClient{} assert.Equal(t, - "\x1b[32mDocument API at "+target+" is ready\n", + "\x1b[32mDocument API at "+target+" is ready\x1b[0m\n", executeCommand(t, client, []string{"status", "document"}, args), "vespa status container") assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String()) @@ -77,7 +78,7 @@ func assertDocumentStatus(target string, args []string, t *testing.T) { func assertQueryStatusError(target string, args []string, t *testing.T) { client := &mockHttpClient{nextStatus: 500} assert.Equal(t, - "\x1b[31mQuery API at "+target+" is not ready\n\x1b[33mStatus 500\n", + "\x1b[31mQuery API at "+target+" is not ready\x1b[0m\n\x1b[33mStatus 500\x1b[0m\n", executeCommand(t, client, []string{"status", "container"}, args), "vespa status container") } diff --git a/client/go/util/print.go b/client/go/util/print.go index ed3a3a1d18a..ce116378222 100644 --- a/client/go/util/print.go +++ b/client/go/util/print.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "os" + "strings" ) // Set this to have output written somewhere else than os.Stdout @@ -67,5 +68,11 @@ func print(prefix string, messages []string) { fmt.Fprint(Out, " ") } } + // TODO: Use "log" instead of this package and something like https://github.com/logrusorgru/aurora for colorization + // Since automatic colorisation needs to support Windows, we probably need github.com/mattn/go-isatty to + // detect TTY + if strings.HasPrefix(prefix, "\033") { + fmt.Fprint(Out, "\033[0m") // Terminate colors + } fmt.Fprintln(Out, "") } |