aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/cmd/status_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/cmd/status_test.go')
-rw-r--r--client/go/cmd/status_test.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/client/go/cmd/status_test.go b/client/go/cmd/status_test.go
new file mode 100644
index 00000000000..0910a6007b9
--- /dev/null
+++ b/client/go/cmd/status_test.go
@@ -0,0 +1,70 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// status command tests
+// Author: bratseth
+
+package cmd
+
+import (
+ "github.com/stretchr/testify/assert"
+ "testing"
+)
+
+func TestStatusConfigServerCommand(t *testing.T) {
+ assertConfigServerStatus("http://127.0.0.1:19071", []string{}, t)
+}
+
+func TestStatusConfigServerCommandWithURLTarget(t *testing.T) {
+ assertConfigServerStatus("http://mydeploytarget", []string{"-t", "http://mydeploytarget"}, t)
+}
+
+func TestStatusConfigServerCommandWithLocalTarget(t *testing.T) {
+ assertConfigServerStatus("http://127.0.0.1:19071", []string{"-t", "local"}, t)
+}
+
+func TestStatusContainerCommand(t *testing.T) {
+ assertContainerStatus("http://127.0.0.1:8080", []string{}, t)
+}
+
+func TestStatusContainerCommandWithUrlTarget(t *testing.T) {
+ assertContainerStatus("http://mycontainertarget", []string{"-t", "http://mycontainertarget"}, t)
+}
+
+func TestStatusContainerCommandWithLocalTarget(t *testing.T) {
+ assertContainerStatus("http://127.0.0.1:8080", []string{"-t", "local"}, t)
+}
+
+func TestStatusErrorResponse(t *testing.T) {
+ assertContainerError("http://127.0.0.1:8080", []string{}, t)
+}
+
+func assertConfigServerStatus(target string, args []string, t *testing.T) {
+ client := &mockHttpClient{}
+ assert.Equal(t,
+ "\x1b[32mConfig server at " + target + " is ready\n",
+ executeCommand(t, client, []string{"status", "config-server"}, args),
+ "vespa status config-server")
+ assert.Equal(t, target + "/ApplicationStatus", client.lastRequest.URL.String())
+}
+
+func assertContainerStatus(target string, args []string, t *testing.T) {
+ client := &mockHttpClient{}
+ assert.Equal(t,
+ "\x1b[32mContainer at " + target + " is ready\n",
+ executeCommand(t, client, []string{"status", "container"}, args),
+ "vespa status container")
+ assert.Equal(t, target + "/ApplicationStatus", client.lastRequest.URL.String())
+
+ assert.Equal(t,
+ "\x1b[32mContainer at " + target + " is ready\n",
+ executeCommand(t, client, []string{"status"}, args),
+ "vespa status (the default)")
+ assert.Equal(t, target + "/ApplicationStatus", client.lastRequest.URL.String())
+}
+
+func assertContainerError(target string, args []string, t *testing.T) {
+ client := &mockHttpClient{ nextStatus: 500,}
+ assert.Equal(t,
+ "\x1b[31mContainer at " + target + " is not ready\n\x1b[33mStatus 500\n",
+ executeCommand(t, client, []string{"status", "container"}, args),
+ "vespa status container")
+} \ No newline at end of file