diff options
author | Martin Polden <mpolden@mpolden.no> | 2023-12-01 10:21:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-01 10:21:56 +0100 |
commit | 0bd3052c7d2150f29ea7277917276aa7d8620a78 (patch) | |
tree | 3412b9bafd9a1e91be897b0b556660f1bf44d2d9 | |
parent | f07ab8bb1d20ddb3457768788ee5a71d7d3c3175 (diff) | |
parent | 3d3649832ef0956cbbb51d3c88761ab198521b5a (diff) |
Merge pull request #29517 from vespa-engine/mpolden/cli-tweaks
More CLI cleanup
20 files changed, 57 insertions, 108 deletions
diff --git a/client/go/internal/admin/deploy/curl.go b/client/go/internal/admin/deploy/curl.go index accd16b06f5..6f77cf8c316 100644 --- a/client/go/internal/admin/deploy/curl.go +++ b/client/go/internal/admin/deploy/curl.go @@ -112,10 +112,6 @@ func curlPutArgs() []string { "--write-out", "\n%{http_code}") } -func curlGetArgs() []string { - return commonCurlArgs() -} - func curlPostArgs() []string { return append(commonCurlArgs(), "--write-out", "\n%{http_code}") diff --git a/client/go/internal/admin/jvm/mem_avail.go b/client/go/internal/admin/jvm/mem_avail.go index df5acf79043..661d42fed28 100644 --- a/client/go/internal/admin/jvm/mem_avail.go +++ b/client/go/internal/admin/jvm/mem_avail.go @@ -28,16 +28,6 @@ func parseFree(txt string) AmountOfMemory { return BytesOfMemory(0) } -func parentDir(dir string) string { - lastSlash := 0 - for idx, ch := range dir { - if ch == '/' { - lastSlash = idx - } - } - return dir[:lastSlash] -} - func readLineFrom(filename string) (string, error) { content, err := os.ReadFile(filename) s := string(content) diff --git a/client/go/internal/admin/vespa-wrapper/logfmt/formatflags_test.go b/client/go/internal/admin/vespa-wrapper/logfmt/formatflags_test.go index 42f82b4361f..39ba18b1255 100644 --- a/client/go/internal/admin/vespa-wrapper/logfmt/formatflags_test.go +++ b/client/go/internal/admin/vespa-wrapper/logfmt/formatflags_test.go @@ -3,14 +3,12 @@ package logfmt import ( "fmt" - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestOutputFormat(t *testing.T) { - type args struct { - val string - } tests := []struct { expected OutputFormat arg string diff --git a/client/go/internal/cli/cmd/api_key.go b/client/go/internal/cli/cmd/api_key.go index d882c527516..938b6623b0b 100644 --- a/client/go/internal/cli/cmd/api_key.go +++ b/client/go/internal/cli/cmd/api_key.go @@ -72,7 +72,7 @@ func doApiKey(cli *CLI, overwriteKey bool, args []string) error { } apiKeyFile := cli.config.apiKeyPath(app.Tenant) if ioutil.Exists(apiKeyFile) && !overwriteKey { - err := fmt.Errorf("refusing to overwrite %s", apiKeyFile) + err := fmt.Errorf("refusing to overwrite '%s'", apiKeyFile) cli.printErr(err, "Use -f to overwrite it") printPublicKey(system, apiKeyFile, app.Tenant) return ErrCLI{error: err, quiet: true} @@ -82,17 +82,17 @@ func doApiKey(cli *CLI, overwriteKey bool, args []string) error { return fmt.Errorf("could not create api key: %w", err) } if err := os.WriteFile(apiKeyFile, apiKey, 0600); err == nil { - cli.printSuccess("Developer private key written to ", apiKeyFile) + cli.printSuccess("Developer private key for tenant ", color.CyanString(app.Tenant), " written to '", apiKeyFile, "'") return printPublicKey(system, apiKeyFile, app.Tenant) } else { - return fmt.Errorf("failed to write: %s: %w", apiKeyFile, err) + return fmt.Errorf("failed to write: '%s': %w", apiKeyFile, err) } } func printPublicKey(system vespa.System, apiKeyFile, tenant string) error { pemKeyData, err := os.ReadFile(apiKeyFile) if err != nil { - return fmt.Errorf("failed to read: %s: %w", apiKeyFile, err) + return fmt.Errorf("failed to read: '%s': %w", apiKeyFile, err) } key, err := vespa.ECPrivateKeyFrom(pemKeyData) if err != nil { diff --git a/client/go/internal/cli/cmd/api_key_test.go b/client/go/internal/cli/cmd/api_key_test.go index 18baec91e0c..8876aedd3fc 100644 --- a/client/go/internal/cli/cmd/api_key_test.go +++ b/client/go/internal/cli/cmd/api_key_test.go @@ -25,7 +25,7 @@ func testAPIKey(t *testing.T, subcommand []string) { err = cli.Run(args...) assert.Nil(t, err) assert.Equal(t, "", stderr.String()) - assert.Contains(t, stdout.String(), "Success: Developer private key written to") + assert.Contains(t, stdout.String(), "Success: Developer private key for tenant t1 written to") err = cli.Run(subcommand...) assert.NotNil(t, err) diff --git a/client/go/internal/cli/cmd/cert.go b/client/go/internal/cli/cmd/cert.go index 3e18fafb815..14e4861cec3 100644 --- a/client/go/internal/cli/cmd/cert.go +++ b/client/go/internal/cli/cmd/cert.go @@ -123,10 +123,10 @@ func doCert(cli *CLI, overwriteCertificate, skipApplicationPackage bool, args [] if !overwriteCertificate { hint := "Use -f flag to force overwriting" if ioutil.Exists(privateKeyFile.path) { - return errHint(fmt.Errorf("private key %s already exists", color.CyanString(privateKeyFile.path)), hint) + return errHint(fmt.Errorf("private key '%s' already exists", color.CyanString(privateKeyFile.path)), hint) } if ioutil.Exists(certificateFile.path) { - return errHint(fmt.Errorf("certificate %s already exists", color.CyanString(certificateFile.path)), hint) + return errHint(fmt.Errorf("certificate '%s' already exists", color.CyanString(certificateFile.path)), hint) } } @@ -140,8 +140,8 @@ func doCert(cli *CLI, overwriteCertificate, skipApplicationPackage bool, args [] if err := keyPair.WritePrivateKeyFile(privateKeyFile.path, overwriteCertificate); err != nil { return fmt.Errorf("could not write private key: %w", err) } - cli.printSuccess("Certificate written to ", color.CyanString(certificateFile.path)) - cli.printSuccess("Private key written to ", color.CyanString(privateKeyFile.path)) + cli.printSuccess("Certificate written to ", color.CyanString("'"+certificateFile.path+"'")) + cli.printSuccess("Private key written to ", color.CyanString("'"+privateKeyFile.path+"'")) if !skipApplicationPackage { return doCertAdd(cli, overwriteCertificate, args) } @@ -158,7 +158,7 @@ func doCertAdd(cli *CLI, overwriteCertificate bool, args []string) error { return err } if pkg.HasCertificate() && !overwriteCertificate { - return errHint(fmt.Errorf("application package %s already contains a certificate", pkg.Path), "Use -f flag to force overwriting") + return errHint(fmt.Errorf("application package '%s' already contains a certificate", pkg.Path), "Use -f flag to force overwriting") } return maybeCopyCertificate(true, false, cli, target, pkg) } @@ -166,13 +166,13 @@ func doCertAdd(cli *CLI, overwriteCertificate bool, args []string) error { func maybeCopyCertificate(force, ignoreZip bool, cli *CLI, target vespa.Target, pkg vespa.ApplicationPackage) error { if pkg.IsZip() { if ignoreZip { - cli.printWarning("Cannot verify existence of "+color.CyanString("security/clients.pem")+" since "+pkg.Path+" is compressed", + cli.printWarning("Cannot verify existence of "+color.CyanString("security/clients.pem")+" since '"+pkg.Path+"' is compressed", "Deployment to Vespa Cloud requires certificate in application package", "See https://cloud.vespa.ai/en/security/guide") return nil } else { hint := "Try running 'mvn clean', then 'vespa auth cert add' and finally 'mvn package'" - return errHint(fmt.Errorf("cannot add certificate to compressed application package: %s", pkg.Path), hint) + return errHint(fmt.Errorf("cannot add certificate to compressed application package: '%s'", pkg.Path), hint) } } if force { @@ -215,7 +215,7 @@ func copyCertificate(cli *CLI, target vespa.Target, pkg vespa.ApplicationPackage } err = ioutil.AtomicWriteFile(dstPath, data) if err == nil { - cli.printSuccess("Copied certificate from ", tlsOptions.CertificateFile, " to ", dstPath) + cli.printSuccess("Copied certificate from '", tlsOptions.CertificateFile, "' to '", dstPath, "'") } return err } diff --git a/client/go/internal/cli/cmd/cert_test.go b/client/go/internal/cli/cmd/cert_test.go index 61e90e21176..10241d0483c 100644 --- a/client/go/internal/cli/cmd/cert_test.go +++ b/client/go/internal/cli/cmd/cert_test.go @@ -46,7 +46,7 @@ func testCert(t *testing.T, subcommand []string) { certificate := filepath.Join(homeDir, app.String(), "data-plane-public-cert.pem") privateKey := filepath.Join(homeDir, app.String(), "data-plane-private-key.pem") - assert.Equal(t, fmt.Sprintf("Success: Certificate written to %s\nSuccess: Private key written to %s\nSuccess: Copied certificate from %s to %s\n", certificate, privateKey, certificate, pkgCertificate), stdout.String()) + assert.Equal(t, fmt.Sprintf("Success: Certificate written to '%s'\nSuccess: Private key written to '%s'\nSuccess: Copied certificate from '%s' to '%s'\n", certificate, privateKey, certificate, pkgCertificate), stdout.String()) } func TestCertCompressedPackage(t *testing.T) { @@ -87,13 +87,13 @@ func TestCertAdd(t *testing.T) { pkgCertificate := filepath.Join(appDir, "security", "clients.pem") homeDir := cli.config.homeDir certificate := filepath.Join(homeDir, "t1.a1.i1", "data-plane-public-cert.pem") - assert.Equal(t, fmt.Sprintf("Success: Copied certificate from %s to %s\n", certificate, pkgCertificate), stdout.String()) + assert.Equal(t, fmt.Sprintf("Success: Copied certificate from '%s' to '%s'\n", certificate, pkgCertificate), stdout.String()) require.NotNil(t, cli.Run("auth", "cert", "add", pkgDir)) - assert.Contains(t, stderr.String(), fmt.Sprintf("Error: application package %s already contains a certificate", appDir)) + assert.Contains(t, stderr.String(), fmt.Sprintf("Error: application package '%s' already contains a certificate", appDir)) stdout.Reset() require.Nil(t, cli.Run("auth", "cert", "add", "-f", pkgDir)) - assert.Equal(t, fmt.Sprintf("Success: Copied certificate from %s to %s\n", certificate, pkgCertificate), stdout.String()) + assert.Equal(t, fmt.Sprintf("Success: Copied certificate from '%s' to '%s'\n", certificate, pkgCertificate), stdout.String()) } func TestCertNoAdd(t *testing.T) { @@ -108,17 +108,17 @@ func TestCertNoAdd(t *testing.T) { certificate := filepath.Join(homeDir, app.String(), "data-plane-public-cert.pem") privateKey := filepath.Join(homeDir, app.String(), "data-plane-private-key.pem") - assert.Equal(t, fmt.Sprintf("Success: Certificate written to %s\nSuccess: Private key written to %s\n", certificate, privateKey), stdout.String()) + assert.Equal(t, fmt.Sprintf("Success: Certificate written to '%s'\nSuccess: Private key written to '%s'\n", certificate, privateKey), stdout.String()) require.NotNil(t, cli.Run("auth", "cert", "-N")) - assert.Contains(t, stderr.String(), fmt.Sprintf("Error: private key %s already exists", privateKey)) + assert.Contains(t, stderr.String(), fmt.Sprintf("Error: private key '%s' already exists", privateKey)) require.Nil(t, os.Remove(privateKey)) stderr.Reset() require.NotNil(t, cli.Run("auth", "cert", "-N")) - assert.Contains(t, stderr.String(), fmt.Sprintf("Error: certificate %s already exists", certificate)) + assert.Contains(t, stderr.String(), fmt.Sprintf("Error: certificate '%s' already exists", certificate)) stdout.Reset() require.Nil(t, cli.Run("auth", "cert", "-N", "-f")) - assert.Equal(t, fmt.Sprintf("Success: Certificate written to %s\nSuccess: Private key written to %s\n", certificate, privateKey), stdout.String()) + assert.Equal(t, fmt.Sprintf("Success: Certificate written to '%s'\nSuccess: Private key written to '%s'\n", certificate, privateKey), stdout.String()) } diff --git a/client/go/internal/cli/cmd/config.go b/client/go/internal/cli/cmd/config.go index a656279549a..fc6d69aab61 100644 --- a/client/go/internal/cli/cmd/config.go +++ b/client/go/internal/cli/cmd/config.go @@ -33,9 +33,9 @@ func newConfigCmd() *cobra.Command { Short: "Manage persistent values for global flags", Long: `Manage persistent values for global flags. -This command allows setting persistent values for global flags. On future -invocations the flag can then be omitted as it is read from the config file -instead. +This command allows setting persistent values for the global flags found in +Vespa CLI. On future invocations the flag can then be omitted as it is read + from the config file instead. Configuration is written to $HOME/.vespa by default. This path can be overridden by setting the VESPA_CLI_HOME environment variable. @@ -58,16 +58,16 @@ The following global flags/options can be configured: application Specifies the application ID to manage. It has three parts, separated by -dots, with the third part being optional. If the part is omitted it defaults to -"default". This is only relevant for the "cloud" and "hosted" targets. See -https://cloud.vespa.ai/en/tenant-apps-instances for more details. This has no -default value. Examples: tenant1.app1, tenant1.app1.instance1 +dots, with the third part being optional. If the third part is omitted it +defaults to "default". This is only relevant for the "cloud" and "hosted" +targets. See https://cloud.vespa.ai/en/tenant-apps-instances for more details. +This has no default value. Examples: tenant1.app1, tenant1.app1.instance1 cluster Specifies the container cluster to manage. If left empty (default) and the application has only one container cluster, that cluster is chosen -automatically. When an application has multiple cluster this must be set a +automatically. When an application has multiple cluster this must specify a valid cluster name, as specified in services.xml. See https://docs.vespa.ai/en/reference/services-container.html for more details. @@ -80,9 +80,9 @@ colors if supported by the terminal, "never" completely disables colors and instance Specifies the instance of the application to manage. When specified, this takes -precedence over the instance specified as part of application. This has no -default value and is only relevant for the "cloud" and "hosted" targets. -Example: instance2 +precedence over the instance specified as part of the 'application' option. +This has no default value and is only relevant for the "cloud" and "hosted" +targets. Example: instance2 quiet @@ -107,7 +107,7 @@ e.g. vespa deploy or vespa query. Possible values are: Authentication is configured automatically for the cloud and hosted targets. To set a custom private key and certificate, e.g. for use with a self-hosted Vespa -installation using mTLS, see the documentation of 'vespa cert'. +installation configured with mTLS, see the documentation of 'vespa auth cert'. zone diff --git a/client/go/internal/cli/cmd/deploy.go b/client/go/internal/cli/cmd/deploy.go index c9331a540eb..9ae6676bc17 100644 --- a/client/go/internal/cli/cmd/deploy.go +++ b/client/go/internal/cli/cmd/deploy.go @@ -86,9 +86,9 @@ $ vespa deploy -t cloud -z perf.aws-us-east-1c`, } log.Println() if opts.Target.IsCloud() { - cli.printSuccess("Triggered deployment of ", color.CyanString(pkg.Path), " with run ID ", color.CyanString(strconv.FormatInt(result.ID, 10))) + cli.printSuccess("Triggered deployment of ", color.CyanString("'"+pkg.Path+"'"), " with run ID ", color.CyanString(strconv.FormatInt(result.ID, 10))) } else { - cli.printSuccess("Deployed ", color.CyanString(pkg.Path), " with session ID ", color.CyanString(strconv.FormatInt(result.ID, 10))) + cli.printSuccess("Deployed ", color.CyanString("'"+pkg.Path+"'"), " with session ID ", color.CyanString(strconv.FormatInt(result.ID, 10))) printPrepareLog(cli.Stderr, result) } if opts.Target.IsCloud() { @@ -133,7 +133,7 @@ func newPrepareCmd(cli *CLI) *cobra.Command { if err := cli.config.writeSessionID(vespa.DefaultApplication, result.ID); err != nil { return fmt.Errorf("could not write session id: %w", err) } - cli.printSuccess("Prepared ", color.CyanString(pkg.Path), " with session ", result.ID) + cli.printSuccess("Prepared ", color.CyanString("'"+pkg.Path+"'"), " with session ", result.ID) printPrepareLog(cli.Stderr, result) return nil }, diff --git a/client/go/internal/cli/cmd/deploy_test.go b/client/go/internal/cli/cmd/deploy_test.go index f34faa21de1..4e32b9bbd60 100644 --- a/client/go/internal/cli/cmd/deploy_test.go +++ b/client/go/internal/cli/cmd/deploy_test.go @@ -84,7 +84,7 @@ func TestDeployWait(t *testing.T) { mockServiceStatus(client, "foo") // Look up services assert.Nil(t, cli.Run("deploy", "--wait=3", pkg)) assert.Equal(t, - "\nSuccess: Deployed "+pkg+" with session ID 1\n", + "\nSuccess: Deployed '"+pkg+"' with session ID 1\n", stdout.String()) } @@ -112,7 +112,7 @@ func TestDeployZipWithURLTargetArgument(t *testing.T) { cli.httpClient = client assert.Nil(t, cli.Run(arguments...)) assert.Equal(t, - "\nSuccess: Deployed "+applicationPackage+" with session ID 0\n", + "\nSuccess: Deployed '"+applicationPackage+"' with session ID 0\n", stdout.String()) assertDeployRequestMade("http://target:19071", client, t) } @@ -188,7 +188,7 @@ func assertDeploy(applicationPackage string, arguments []string, t *testing.T) { cli.httpClient = client assert.Nil(t, cli.Run(arguments...)) assert.Equal(t, - "\nSuccess: Deployed "+applicationPackage+" with session ID 0\n", + "\nSuccess: Deployed '"+applicationPackage+"' with session ID 0\n", stdout.String()) assertDeployRequestMade("http://127.0.0.1:19071", client, t) } @@ -202,7 +202,7 @@ func assertPrepare(applicationPackage string, arguments []string, t *testing.T) cli.httpClient = client assert.Nil(t, cli.Run(arguments...)) assert.Equal(t, - "Success: Prepared "+applicationPackage+" with session 42\n", + "Success: Prepared '"+applicationPackage+"' with session 42\n", stdout.String()) assertPackageUpload(0, "http://127.0.0.1:19071/application/v2/tenant/default/session", client, t) diff --git a/client/go/internal/cli/cmd/gendoc.go b/client/go/internal/cli/cmd/gendoc.go index 62415111035..c440805cb9e 100644 --- a/client/go/internal/cli/cmd/gendoc.go +++ b/client/go/internal/cli/cmd/gendoc.go @@ -11,7 +11,7 @@ import ( func newGendocCmd(cli *CLI) *cobra.Command { return &cobra.Command{ Use: "gendoc directory", - Short: "Generate documentation from '--help' pages and write as markdown files to a given directory", + Short: "Generate documentation from '--help' pages and write as Markdown files to a given directory", Args: cobra.ExactArgs(1), Hidden: true, // Not intended to be called by users DisableAutoGenTag: true, diff --git a/client/go/internal/cli/cmd/prod.go b/client/go/internal/cli/cmd/prod.go index 0912ca31e25..620ec055a1d 100644 --- a/client/go/internal/cli/cmd/prod.go +++ b/client/go/internal/cli/cmd/prod.go @@ -63,7 +63,7 @@ https://cloud.vespa.ai/en/reference/deployment`, return err } if pkg.IsZip() { - return errHint(fmt.Errorf("cannot modify compressed application package %s", pkg.Path), + return errHint(fmt.Errorf("cannot modify compressed application package '%s'", pkg.Path), "Try running 'mvn clean' and run this command again") } @@ -169,7 +169,7 @@ $ vespa prod deploy`, if err != nil { return fmt.Errorf("could not deploy application: %w", err) } else { - cli.printSuccess(fmt.Sprintf("Deployed %s with build number %s", color.CyanString(pkg.Path), color.CyanString(strconv.FormatInt(build, 10)))) + cli.printSuccess(fmt.Sprintf("Deployed '%s' with build number %s", color.CyanString(pkg.Path), color.CyanString(strconv.FormatInt(build, 10)))) log.Printf("See %s for deployment progress\n", color.CyanString(fmt.Sprintf("%s/tenant/%s/application/%s/prod/deployment", deployment.Target.Deployment().System.ConsoleURL, deployment.Target.Deployment().Application.Tenant, deployment.Target.Deployment().Application.Application))) } @@ -317,7 +317,7 @@ func promptNodeCount(cli *CLI, stdin *bufio.Reader, clusterID string, nodeCount validator := func(input string) error { min, _, err := xml.ParseNodeCount(input) if min < 2 { - return fmt.Errorf("at least 2 nodes are required for all clusters in a production environment.\nSee https://cloud.vespa.ai/en/production-deployment for more details.") + return errHint(fmt.Errorf("at least 2 nodes are required for all clusters in a production environment, got %d", min), "See https://cloud.vespa.ai/en/production-deployment") } return err } diff --git a/client/go/internal/cli/cmd/prod_test.go b/client/go/internal/cli/cmd/prod_test.go index 6d8a50124ac..e2b0b3b88de 100644 --- a/client/go/internal/cli/cmd/prod_test.go +++ b/client/go/internal/cli/cmd/prod_test.go @@ -3,7 +3,6 @@ package cmd import ( "bytes" - "io" "os" "path/filepath" "strings" @@ -190,12 +189,12 @@ func prodDeploy(pkgDir string, t *testing.T) { cli.Environment["VESPA_CLI_API_KEY_FILE"] = filepath.Join(cli.config.homeDir, "t1.api-key.pem") httpClient.NextResponseString(200, `{"build": 42}`) assert.Nil(t, cli.Run("prod", "deploy", "--add-cert")) - assert.Contains(t, stdout.String(), "Success: Deployed . with build number 42") + assert.Contains(t, stdout.String(), "Success: Deployed '.' with build number 42") assert.Contains(t, stdout.String(), "See https://console.vespa-cloud.com/tenant/t1/application/a1/prod/deployment for deployment progress") stdout.Reset() httpClient.NextResponseString(200, `{"build": 43}`) assert.Nil(t, cli.Run("prod", "submit", "--add-cert")) // old variant also works - assert.Contains(t, stdout.String(), "Success: Deployed . with build number 43") + assert.Contains(t, stdout.String(), "Success: Deployed '.' with build number 43") assert.Contains(t, stdout.String(), "See https://console.vespa-cloud.com/tenant/t1/application/a1/prod/deployment for deployment progress") } @@ -216,7 +215,7 @@ func TestProdDeployWithJava(t *testing.T) { cli.Environment["VESPA_CLI_API_KEY_FILE"] = filepath.Join(cli.config.homeDir, "t1.api-key.pem") assert.Nil(t, cli.Run("prod", "deploy", "--add-cert", pkgDir)) assert.Equal(t, "", stderr.String()) - assert.Contains(t, stdout.String(), "Success: Deployed "+pkgDir+"/target/application with build number 42") + assert.Contains(t, stdout.String(), "Success: Deployed '"+pkgDir+"/target/application' with build number 42") assert.Contains(t, stdout.String(), "See https://console.vespa-cloud.com/tenant/t1/application/a1/prod/deployment for deployment progress") } @@ -239,19 +238,3 @@ func TestProdDeployInvalidZip(t *testing.T) { assert.NotNil(t, cli.Run("prod", "deploy", zipFile)) assert.Equal(t, "Error: found invalid path inside zip: ../../../../../../../tmp/foo\n", stderr.String()) } - -func copyFile(t *testing.T, dstFilename, srcFilename string) { - dst, err := os.Create(dstFilename) - if err != nil { - t.Fatal(err) - } - defer dst.Close() - src, err := os.Open(srcFilename) - if err != nil { - t.Fatal(err) - } - defer src.Close() - if _, err := io.Copy(dst, src); err != nil { - t.Fatal(err) - } -} diff --git a/client/go/internal/cli/cmd/status_test.go b/client/go/internal/cli/cmd/status_test.go index 8bd8449d5a1..3c6277b9050 100644 --- a/client/go/internal/cli/cmd/status_test.go +++ b/client/go/internal/cli/cmd/status_test.go @@ -228,19 +228,3 @@ func assertStatus(expectedTarget string, args []string, t *testing.T) { assert.Nil(t, cli.Run(append(statusArgs, args...)...)) assert.Equal(t, expectedTarget+"\n", stdout.String()) } - -func assertDocumentStatus(target string, args []string, t *testing.T) { - t.Helper() - client := &mock.HTTPClient{} - if isLocalTarget(args) { - mockServiceStatus(client, "default") - } - cli, stdout, _ := newTestCLI(t) - cli.httpClient = client - assert.Nil(t, cli.Run("status", "document")) - assert.Equal(t, - "Container (document API) at "+target+" is ready\n", - stdout.String(), - "vespa status container") - assert.Equal(t, target+"/status.html", client.LastRequest.URL.String()) -} diff --git a/client/go/internal/mock/http.go b/client/go/internal/mock/http.go index 06e143ab80d..2fbaa85ecca 100644 --- a/client/go/internal/mock/http.go +++ b/client/go/internal/mock/http.go @@ -8,8 +8,6 @@ import ( "net/http" "strconv" "time" - - "github.com/vespa-engine/vespa/client/go/internal/httputil" ) type HTTPClient struct { @@ -94,5 +92,3 @@ func (c *HTTPClient) Do(request *http.Request, timeout time.Duration) (*http.Res }, nil } - -func (c *HTTPClient) Clone() httputil.Client { return c } diff --git a/client/go/internal/osutil/fix_fs.go b/client/go/internal/osutil/fix_fs.go index 837624cc05b..f59ee8bca83 100644 --- a/client/go/internal/osutil/fix_fs.go +++ b/client/go/internal/osutil/fix_fs.go @@ -68,7 +68,7 @@ func (spec *FixSpec) FixDir(dirName string) { spec.complainAndExit(err, dirName, spec.DirMode) } if !info.IsDir() { - err = fmt.Errorf("Not a directory: '%s'", dirName) + err = fmt.Errorf("not a directory: '%s'", dirName) spec.complainAndExit(err, dirName, spec.DirMode) } trace.SpamDebug("chown: ", dirName, spec.UserId, spec.GroupId) @@ -95,7 +95,7 @@ func (spec *FixSpec) FixFile(fileName string) { return } if info.IsDir() { - err = fmt.Errorf("Should not be a directory: '%s'", fileName) + err = fmt.Errorf("should not be a directory: '%s'", fileName) spec.complainAndExit(err, fileName, spec.FileMode) } trace.SpamDebug("chown: ", fileName, spec.UserId, spec.GroupId) diff --git a/client/go/internal/osutil/fix_fs_test.go b/client/go/internal/osutil/fix_fs_test.go index 792986d7996..a59f1361b1f 100644 --- a/client/go/internal/osutil/fix_fs_test.go +++ b/client/go/internal/osutil/fix_fs_test.go @@ -23,6 +23,7 @@ func setup(t *testing.T) string { err = os.WriteFile(tmpDir+"/a/f1", []byte{10}, 0644) assert.Nil(t, err) err = os.WriteFile(tmpDir+"/a/f2", []byte{10}, 0111) + assert.Nil(t, err) return tmpDir } @@ -91,6 +92,7 @@ func TestSuperUserOnly(t *testing.T) { return } u, err := user.Current() + assert.Nil(t, err) if u.Username != "root" { trace.Trace("skip TestSuperUserOnly, user != root") return diff --git a/client/go/internal/vespa/application.go b/client/go/internal/vespa/application.go index 5d1ab610e38..a65fb41d783 100644 --- a/client/go/internal/vespa/application.go +++ b/client/go/internal/vespa/application.go @@ -160,7 +160,7 @@ func (ap *ApplicationPackage) zipReader(test bool) (io.ReadCloser, error) { } f, err := os.Open(zipFile) if err != nil { - return nil, fmt.Errorf("could not open application package at %s: %w", ap.Path, err) + return nil, fmt.Errorf("could not open application package at '%s': %w", ap.Path, err) } return f, nil } diff --git a/client/go/internal/vespa/load_env.go b/client/go/internal/vespa/load_env.go index a799cbf4f9a..5cae03694bc 100644 --- a/client/go/internal/vespa/load_env.go +++ b/client/go/internal/vespa/load_env.go @@ -93,7 +93,7 @@ func loadDefaultEnvTo(r loadEnvReceiver) error { varName := fields[1] varVal := fields[2] if !isValidShellVariableName(varName) { - err = fmt.Errorf("Not a valid environment variable name: '%s'", varName) + err = fmt.Errorf("not a valid environment variable name: '%s'", varName) continue } if strings.HasPrefix(varVal, `"`) && strings.HasSuffix(varVal, `"`) { @@ -259,7 +259,7 @@ func (p *shellEnvExporter) dump(w io.Writer) { fmt.Fprintf(w, "%s=%s\n", vn, vv) fmt.Fprintf(w, "export %s\n", vn) } - for vn, _ := range p.unsetVars { + for vn := range p.unsetVars { fmt.Fprintf(w, "unset %s\n", vn) } } diff --git a/client/go/internal/vespa/load_env_test.go b/client/go/internal/vespa/load_env_test.go index ffd553e041d..723354bd1cb 100644 --- a/client/go/internal/vespa/load_env_test.go +++ b/client/go/internal/vespa/load_env_test.go @@ -106,7 +106,7 @@ override VESPA_V2 v2 assert.Equal(t, os.Getenv("VESPA_V1"), "v1") assert.Equal(t, os.Getenv("VESPA_V2"), "v2") assert.NotNil(t, err) - assert.Equal(t, err.Error(), "Not a valid environment variable name: '.A'") + assert.Equal(t, err.Error(), "not a valid environment variable name: '.A'") } func TestFindUser(t *testing.T) { |