summaryrefslogtreecommitdiffstats
path: root/client/go/cmd/status_test.go
blob: fe7228697c7c55832c237db9221d03d6b29fcbff (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright Yahoo. 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"
	"github.com/vespa-engine/vespa/client/go/mock"
)

func TestStatusDeployCommand(t *testing.T) {
	assertDeployStatus("http://127.0.0.1:19071", []string{}, t)
}

func TestStatusDeployCommandWithURLTarget(t *testing.T) {
	assertDeployStatus("http://mydeploytarget:19071", []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:8080", []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 := &mock.HTTPClient{}
	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 := &mock.HTTPClient{}
	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 := &mock.HTTPClient{}
	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 := &mock.HTTPClient{}
	client.NextStatus(500)
	cmd := []string{"status", "container"}
	cmd = append(cmd, args...)
	_, outErr := execute(command{args: cmd}, t, client)
	assert.Equal(t,
		"Error: Container (query API) at "+target+" is not ready: status 500\n",
		outErr,
		"vespa status container")
}