aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/cmd/status_test.go
blob: 0910a6007b959114667a838299eb64d662baf199 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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")
}