diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-08-12 12:15:08 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-08-12 12:15:08 +0200 |
commit | aebeea9723e7c31eb9c2094f6ddf2a26d1db5987 (patch) | |
tree | f458438af1f39dffef47a26e07cd12e7649407e8 | |
parent | 0dd5de48c0a133ba1047fe74127057b40c95aeba (diff) |
Test status command flags
3 files changed, 42 insertions, 17 deletions
diff --git a/client/go/src/github.com/vespa-engine/vespa/cmd/command_tester.go b/client/go/src/github.com/vespa-engine/vespa/cmd/command_tester.go index 70523a1a74d..25c03620eee 100644 --- a/client/go/src/github.com/vespa-engine/vespa/cmd/command_tester.go +++ b/client/go/src/github.com/vespa-engine/vespa/cmd/command_tester.go @@ -23,11 +23,11 @@ func init() { nextStatus = 200 } -func executeCommand(t *testing.T, args []string) (standardout string) { +func executeCommand(t *testing.T, args []string, moreArgs []string) (standardout string) { utils.ActiveHttpClient = mockHttpClient{} b := bytes.NewBufferString("") utils.Out = b - rootCmd.SetArgs(args) + rootCmd.SetArgs(concat(args, moreArgs)) rootCmd.Execute() out, err := ioutil.ReadAll(b) assert.Empty(t, err, "No error") @@ -46,3 +46,14 @@ func (c mockHttpClient) Do(request *http.Request) (response *http.Response, erro }, nil } + +func concat(array1 []string, array2 []string) []string { + result := make([]string, len(array1) + len(array2)) + for i := 0; i < len(array1); i++ { + result[i] = array1[i] + } + for i := 0; i < len(array2); i++ { + result[i + len(array1)] = array2[i] + } + return result +}
\ No newline at end of file diff --git a/client/go/src/github.com/vespa-engine/vespa/cmd/deploy_test.go b/client/go/src/github.com/vespa-engine/vespa/cmd/deploy_test.go index 482ceb86688..389bf7f0d23 100644 --- a/client/go/src/github.com/vespa-engine/vespa/cmd/deploy_test.go +++ b/client/go/src/github.com/vespa-engine/vespa/cmd/deploy_test.go @@ -12,29 +12,29 @@ import ( func TestDeployZip(t *testing.T) { assert.Equal(t, "\x1b[32mSuccess \n", - executeCommand(t, []string{"deploy", "testdata/application.zip"})) + executeCommand(t, []string{"deploy", "testdata/application.zip"}, []string{})) assertDeployRequestMade("http://127.0.0.1:19071", t) } func TestDeployZipWithTargetArgument(t *testing.T) { assert.Equal(t, "\x1b[32mSuccess \n", - executeCommand(t, []string{"deploy", "testdata/application.zip", "-d", "http://target:19071"})) + executeCommand(t, []string{"deploy", "testdata/application.zip", "-d", "http://target:19071"}, []string{})) assertDeployRequestMade("http://target:19071", t) assert.Equal(t, "\x1b[32mSuccess \n", - executeCommand(t, []string{"deploy", "testdata/application.zip", "--deploy-target", "http://target2:19071"})) + executeCommand(t, []string{"deploy", "testdata/application.zip", "--deploy-target", "http://target2:19071"}, []string{})) assertDeployRequestMade("http://target2:19071", t) // Reset persistent flag - executeCommand(t, []string{"deploy", "testdata/application.zip", "-d", "http://127.0.0.1:19071"}) + executeCommand(t, []string{"deploy", "testdata/application.zip", "-d", "http://127.0.0.1:19071"}, []string{}) } func TestDeployDirectory(t *testing.T) { assert.Equal(t, "\x1b[32mSuccess \n", - executeCommand(t, []string{"deploy", "testdata/src/main/application"})) + executeCommand(t, []string{"deploy", "testdata/src/main/application"}, []string{})) assertDeployRequestMade("http://127.0.0.1:19071", t) } diff --git a/client/go/src/github.com/vespa-engine/vespa/cmd/status_test.go b/client/go/src/github.com/vespa-engine/vespa/cmd/status_test.go index 12a54a6bd8c..b9d36089a71 100644 --- a/client/go/src/github.com/vespa-engine/vespa/cmd/status_test.go +++ b/client/go/src/github.com/vespa-engine/vespa/cmd/status_test.go @@ -10,43 +10,57 @@ import ( ) func TestStatusConfigServerCommand(t *testing.T) { - assertConfigServerStatus("http://127.0.0.1:19071", t) + assertConfigServerStatus("http://127.0.0.1:19071", []string{}, t) +} + +func TestStatusConfigServerCommandWithTarget(t *testing.T) { + assertConfigServerStatus("http://mydeploytarget", []string{"-d", "http://mydeploytarget"}, t) + + // Reset persistent flag + executeCommand(t, []string{"status", "container", "-d", "http://127.0.0.1:19071"}, []string{}) } func TestStatusContainerCommand(t *testing.T) { - assertContainerStatus("http://127.0.0.1:8080", t) + assertContainerStatus("http://127.0.0.1:8080", []string{}, t) +} + +func TestStatusContainerCommandWithTarget(t *testing.T) { + assertContainerStatus("http://mycontainertarget", []string{"-c", "http://mycontainertarget"}, t) + + // Reset persistent flag + executeCommand(t, []string{"status", "container", "-c", "http://127.0.0.1:8080"}, []string{}) } func TestStatusErrorResponse(t *testing.T) { - assertContainerError("http://127.0.0.1:8080", t) + assertContainerError("http://127.0.0.1:8080", []string{}, t) } -func assertConfigServerStatus(target string, t *testing.T) { +func assertConfigServerStatus(target string, args []string, t *testing.T) { assert.Equal(t, "\x1b[32mConfig server at " + target + " is ready \n", - executeCommand(t, []string{"status", "config-server"}), + executeCommand(t, []string{"status", "config-server"}, args), "vespa status config-server") assert.Equal(t, target + "/ApplicationStatus", lastRequest.URL.String()) } -func assertContainerStatus(target string, t *testing.T) { +func assertContainerStatus(target string, args []string, t *testing.T) { assert.Equal(t, "\x1b[32mContainer at " + target + " is ready \n", - executeCommand(t, []string{"status", "container"}), + executeCommand(t, []string{"status", "container"}, args), "vespa status container") assert.Equal(t, target + "/ApplicationStatus", lastRequest.URL.String()) assert.Equal(t, "\x1b[32mContainer at " + target + " is ready \n", - executeCommand(t, []string{"status"}), + executeCommand(t, []string{"status"}, args), "vespa status (the default)") assert.Equal(t, target + "/ApplicationStatus", lastRequest.URL.String()) } -func assertContainerError(target string, t *testing.T) { +func assertContainerError(target string, args []string, t *testing.T) { nextStatus = 500 assert.Equal(t, "\x1b[31mContainer at " + target + " is not ready \n\x1b[33mResponse status: \n", - executeCommand(t, []string{"status", "container"}), + executeCommand(t, []string{"status", "container"}, args), "vespa status container") }
\ No newline at end of file |