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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// 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 (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStatusDeployCommand(t *testing.T) {
assertDeployStatus("http://127.0.0.1:19071", []string{}, t)
}
func TestStatusDeployCommandWithURLTarget(t *testing.T) {
assertDeployStatus("http://mydeploytarget", []string{"-t", "http://mydeploytarget"}, t)
}
func TestStatusDeployCommandWithLocalTarget(t *testing.T) {
assertDeployStatus("http://127.0.0.1:19071", []string{"-t", "local"}, t)
}
func TestStatusQueryCommand(t *testing.T) {
assertQueryStatus("http://127.0.0.1:8080", []string{}, t)
}
func TestStatusQueryCommandWithUrlTarget(t *testing.T) {
assertQueryStatus("http://mycontainertarget", []string{"-t", "http://mycontainertarget"}, t)
}
func TestStatusQueryCommandWithLocalTarget(t *testing.T) {
assertQueryStatus("http://127.0.0.1:8080", []string{"-t", "local"}, t)
}
func TestStatusDocumentCommandWithLocalTarget(t *testing.T) {
assertDocumentStatus("http://127.0.0.1:8080", []string{"-t", "local"}, t)
}
func TestStatusErrorResponse(t *testing.T) {
assertQueryStatusError("http://127.0.0.1:8080", []string{}, t)
}
func assertDeployStatus(target string, args []string, t *testing.T) {
client := &mockHttpClient{}
assert.Equal(t,
"Deploy API at "+target+" is ready\n",
executeCommand(t, client, []string{"status", "deploy"}, args),
"vespa status config-server")
assert.Equal(t, target+"/status.html", client.lastRequest.URL.String())
}
func assertQueryStatus(target string, args []string, t *testing.T) {
client := &mockHttpClient{}
assert.Equal(t,
"Container (query API) at "+target+" is ready\n",
executeCommand(t, client, []string{"status", "query"}, args),
"vespa status container")
assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String())
assert.Equal(t,
"Container (query API) 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 assertDocumentStatus(target string, args []string, t *testing.T) {
client := &mockHttpClient{}
assert.Equal(t,
"Container (document API) at "+target+" is ready\n",
executeCommand(t, client, []string{"status", "document"}, args),
"vespa status container")
assert.Equal(t, target+"/ApplicationStatus", client.lastRequest.URL.String())
}
func assertQueryStatusError(target string, args []string, t *testing.T) {
client := &mockHttpClient{nextStatus: 500}
assert.Equal(t,
"Container (query API) at "+target+" is not ready\nStatus 500\n",
executeCommand(t, client, []string{"status", "container"}, args),
"vespa status container")
}
|