diff options
Diffstat (limited to 'client/go/cmd/curl_test.go')
-rw-r--r-- | client/go/cmd/curl_test.go | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/client/go/cmd/curl_test.go b/client/go/cmd/curl_test.go index 50b837e0d85..520cf41e308 100644 --- a/client/go/cmd/curl_test.go +++ b/client/go/cmd/curl_test.go @@ -3,38 +3,34 @@ package cmd import ( "fmt" - "os" "path/filepath" "testing" "github.com/stretchr/testify/assert" - "github.com/vespa-engine/vespa/client/go/mock" ) func TestCurl(t *testing.T) { - homeDir := filepath.Join(t.TempDir(), ".vespa") - httpClient := &mock.HTTPClient{} - _, outErr := execute(command{args: []string{"config", "set", "application", "t1.a1.i1"}, homeDir: homeDir}, t, nil) - assert.Equal(t, "", outErr) - _, outErr = execute(command{args: []string{"config", "set", "target", "cloud"}, homeDir: homeDir}, t, nil) - assert.Equal(t, "", outErr) - _, outErr = execute(command{args: []string{"auth", "api-key"}, homeDir: homeDir}, t, nil) - assert.Equal(t, "", outErr) - _, outErr = execute(command{args: []string{"auth", "cert", "--no-add"}, homeDir: homeDir}, t, nil) - assert.Equal(t, "", outErr) + cli, stdout, _ := newTestCLI(t) + cli.Environment["VESPA_CLI_ENDPOINTS"] = "{\"endpoints\":[{\"cluster\":\"container\",\"url\":\"http://127.0.0.1:8080\"}]}" + assert.Nil(t, cli.Run("config", "set", "application", "t1.a1.i1")) + assert.Nil(t, cli.Run("config", "set", "target", "cloud")) + assert.Nil(t, cli.Run("auth", "api-key")) + assert.Nil(t, cli.Run("auth", "cert", "--no-add")) - os.Setenv("VESPA_CLI_ENDPOINTS", "{\"endpoints\":[{\"cluster\":\"container\",\"url\":\"http://127.0.0.1:8080\"}]}") - out, _ := execute(command{homeDir: homeDir, args: []string{"curl", "-n", "--", "-v", "--data-urlencode", "arg=with space", "/search"}}, t, httpClient) + stdout.Reset() + err := cli.Run("curl", "-n", "--", "-v", "--data-urlencode", "arg=with space", "/search") + assert.Nil(t, err) expected := fmt.Sprintf("curl --key %s --cert %s -v --data-urlencode 'arg=with space' http://127.0.0.1:8080/search\n", - 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) + filepath.Join(cli.config.homeDir, "t1.a1.i1", "data-plane-private-key.pem"), + filepath.Join(cli.config.homeDir, "t1.a1.i1", "data-plane-public-cert.pem")) + assert.Equal(t, expected, stdout.String()) - _, outErr = execute(command{args: []string{"config", "set", "target", "local"}, homeDir: homeDir}, t, nil) - assert.Equal(t, "", outErr) - out, outErr = execute(command{homeDir: homeDir, args: []string{"curl", "-a", "t1.a1.i1", "-s", "deploy", "-n", "/application/v4/tenant/foo"}}, t, httpClient) - assert.Equal(t, "", outErr) + assert.Nil(t, cli.Run("config", "set", "target", "local")) + + stdout.Reset() + err = cli.Run("curl", "-a", "t1.a1.i1", "-s", "deploy", "-n", "/application/v4/tenant/foo") + assert.Nil(t, err) expected = "curl http://127.0.0.1:19071/application/v4/tenant/foo\n" - assert.Equal(t, expected, out) + assert.Equal(t, expected, stdout.String()) } |