diff options
author | Martin Polden <mpolden@mpolden.no> | 2021-09-24 15:45:01 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2021-09-24 15:45:01 +0200 |
commit | a352e0c0a88d8d66530f17c8ae7a986930f179e5 (patch) | |
tree | 97e300e04533e7eb0cb84433cb32e15042b3c6a9 /client | |
parent | 6c050fa81dd9dff3c362ea94472e493ae29c05ec (diff) |
Test cleanup
Diffstat (limited to 'client')
-rw-r--r-- | client/go/cmd/api_key_test.go | 12 | ||||
-rw-r--r-- | client/go/cmd/cert_test.go | 8 | ||||
-rw-r--r-- | client/go/cmd/command_tester.go | 4 | ||||
-rw-r--r-- | client/go/cmd/config_test.go | 3 | ||||
-rw-r--r-- | client/go/cmd/curl_test.go | 6 | ||||
-rw-r--r-- | client/go/cmd/deploy_test.go | 2 |
6 files changed, 18 insertions, 17 deletions
diff --git a/client/go/cmd/api_key_test.go b/client/go/cmd/api_key_test.go index 2497568604f..1deb628c21e 100644 --- a/client/go/cmd/api_key_test.go +++ b/client/go/cmd/api_key_test.go @@ -4,20 +4,20 @@ package cmd import ( - "strings" + "path/filepath" "testing" "github.com/stretchr/testify/assert" ) func TestAPIKey(t *testing.T) { - homeDir := t.TempDir() - keyFile := homeDir + "/.vespa/t1.api-key.pem" + homeDir := filepath.Join(t.TempDir(), ".vespa") + keyFile := filepath.Join(homeDir, "t1.api-key.pem") out, _ := execute(command{args: []string{"api-key", "-a", "t1.a1.i1"}, homeDir: homeDir}, t, nil) - assert.True(t, strings.HasPrefix(out, "Success: API private key written to "+keyFile+"\n")) + assert.Contains(t, out, "Success: API private key written to "+keyFile+"\n") out, _ = execute(command{args: []string{"api-key", "-a", "t1.a1.i1"}, homeDir: homeDir}, t, nil) - assert.True(t, strings.HasPrefix(out, "Error: File "+keyFile+" already exists\nHint: Use -f to overwrite it\n")) - assert.True(t, strings.Contains(out, "This is your public key")) + assert.Contains(t, out, "Error: File "+keyFile+" already exists\nHint: Use -f to overwrite it\n") + assert.Contains(t, out, "This is your public key") } diff --git a/client/go/cmd/cert_test.go b/client/go/cmd/cert_test.go index d93def2fa70..cd5f88764b9 100644 --- a/client/go/cmd/cert_test.go +++ b/client/go/cmd/cert_test.go @@ -14,7 +14,7 @@ import ( ) func TestCert(t *testing.T) { - homeDir := t.TempDir() + homeDir := filepath.Join(t.TempDir(), ".vespa") pkgDir := mockApplicationPackage(t, false) out, _ := execute(command{args: []string{"cert", "-a", "t1.a1.i1", pkgDir}, homeDir: homeDir}, t, nil) @@ -23,8 +23,8 @@ func TestCert(t *testing.T) { appDir := filepath.Join(pkgDir, "src", "main", "application") pkgCertificate := filepath.Join(appDir, "security", "clients.pem") - certificate := filepath.Join(homeDir, ".vespa", app.String(), "data-plane-public-cert.pem") - privateKey := filepath.Join(homeDir, ".vespa", app.String(), "data-plane-private-key.pem") + 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: Certificate written to %s\nSuccess: Private key written to %s\n", pkgCertificate, certificate, privateKey), out) @@ -33,7 +33,7 @@ func TestCert(t *testing.T) { } func TestCertCompressedPackage(t *testing.T) { - homeDir := t.TempDir() + homeDir := filepath.Join(t.TempDir(), ".vespa") pkgDir := mockApplicationPackage(t, true) zipFile := filepath.Join(pkgDir, "target", "application.zip") err := os.MkdirAll(filepath.Dir(zipFile), 0755) diff --git a/client/go/cmd/command_tester.go b/client/go/cmd/command_tester.go index f455ffa9957..a0c3183ca4c 100644 --- a/client/go/cmd/command_tester.go +++ b/client/go/cmd/command_tester.go @@ -33,10 +33,10 @@ func execute(cmd command, t *testing.T, client *mockHttpClient) (string, string) // Set config dir. Use a separate one per test if none is specified if cmd.homeDir == "" { - cmd.homeDir = t.TempDir() + cmd.homeDir = filepath.Join(t.TempDir(), ".vespa") viper.Reset() } - os.Setenv("VESPA_CLI_HOME", filepath.Join(cmd.homeDir, ".vespa")) + os.Setenv("VESPA_CLI_HOME", cmd.homeDir) // Reset flags to their default value - persistent flags in Cobra persists over tests rootCmd.Flags().VisitAll(func(f *pflag.Flag) { diff --git a/client/go/cmd/config_test.go b/client/go/cmd/config_test.go index cf50f561f0f..25ba7cc0655 100644 --- a/client/go/cmd/config_test.go +++ b/client/go/cmd/config_test.go @@ -1,13 +1,14 @@ package cmd import ( + "path/filepath" "testing" "github.com/stretchr/testify/assert" ) func TestConfig(t *testing.T) { - homeDir := t.TempDir() + homeDir := filepath.Join(t.TempDir(), ".vespa") assertConfigCommand(t, "invalid option or value: \"foo\": \"bar\"\n", homeDir, "config", "set", "foo", "bar") assertConfigCommand(t, "foo = <unset>\n", homeDir, "config", "get", "foo") assertConfigCommand(t, "target = local\n", homeDir, "config", "get", "target") diff --git a/client/go/cmd/curl_test.go b/client/go/cmd/curl_test.go index 340eacd0bd3..e67ef560c41 100644 --- a/client/go/cmd/curl_test.go +++ b/client/go/cmd/curl_test.go @@ -10,13 +10,13 @@ import ( ) func TestCurl(t *testing.T) { - homeDir := t.TempDir() + homeDir := filepath.Join(t.TempDir(), ".vespa") httpClient := &mockHttpClient{} convergeServices(httpClient) out, _ := execute(command{homeDir: homeDir, args: []string{"curl", "-n", "-a", "t1.a1.i1", "--", "-v", "--data-urlencode", "arg=with space", "/search"}}, t, httpClient) expected := fmt.Sprintf("curl --key %s --cert %s -v --data-urlencode 'arg=with space' https://127.0.0.1:8080/search\n", - filepath.Join(homeDir, ".vespa", "t1.a1.i1", "data-plane-private-key.pem"), - filepath.Join(homeDir, ".vespa", "t1.a1.i1", "data-plane-public-cert.pem")) + filepath.Join(homeDir, "t1.a1.i1", "data-plane-private-key.pem"), + filepath.Join(homeDir, "t1.a1.i1", "data-plane-public-cert.pem")) assert.Equal(t, expected, out) } diff --git a/client/go/cmd/deploy_test.go b/client/go/cmd/deploy_test.go index 443f7e8846f..9614806b968 100644 --- a/client/go/cmd/deploy_test.go +++ b/client/go/cmd/deploy_test.go @@ -130,7 +130,7 @@ func assertActivate(applicationPackage string, arguments []string, t *testing.T) if err := cfg.WriteSessionID(vespa.DefaultApplication, 42); err != nil { t.Fatal(err) } - out, _ := execute(command{args: arguments, homeDir: homeDir}, t, client) + out, _ := execute(command{args: arguments, homeDir: cfg.Home}, t, client) assert.Equal(t, "Success: Activated "+applicationPackage+" with session 42\n", out) |