diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-07-22 12:43:38 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-07-22 12:43:38 +0200 |
commit | de44ed5335b293283864e53c27684b88499caf3c (patch) | |
tree | d3fe51aca05eb347633559db8e971b525ca50da8 /client/go | |
parent | d1f2b4b4e94de46d18ea23c0b1c2722fd133fb5e (diff) |
Record last request
Diffstat (limited to 'client/go')
4 files changed, 27 insertions, 21 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 07ff7ece18c..70523a1a74d 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 @@ -13,7 +13,15 @@ import ( "testing" ) -var expectedUrl string +// The HTTP status code that will be returned from the next invocation. Defauult: 200 +var nextStatus int + +// A recording of the last HTTP request made through this +var lastRequest *http.Request + +func init() { + nextStatus = 200 +} func executeCommand(t *testing.T, args []string) (standardout string) { utils.ActiveHttpClient = mockHttpClient{} @@ -26,22 +34,14 @@ func executeCommand(t *testing.T, args []string) (standardout string) { return string(out) } -type mockHttpClient struct {} +type mockHttpClient struct { +} func (c mockHttpClient) Do(request *http.Request) (response *http.Response, error error) { - var status int - var body string - if request.URL.String() == expectedUrl { - status = 200 - body = "OK" - } else { - status = 400 - body = "Unexpected url " + request.URL.String() - } - + lastRequest = request return &http.Response{ - StatusCode: status, - Body: ioutil.NopCloser(bytes.NewBufferString(body)), + StatusCode: nextStatus, + Body: ioutil.NopCloser(bytes.NewBufferString("")), Header: make(http.Header), }, nil diff --git a/client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go b/client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go index 2067c2f4034..f69072e62ca 100644 --- a/client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go +++ b/client/go/src/github.com/vespa-engine/vespa/cmd/deploy.go @@ -46,7 +46,12 @@ func deploy(application string) { } url, _ := url.Parse("http://127.0.0.1:19071/application/v2/tenant/default/prepareandactivate") - request := &http.Request{URL: url,} + header := http.Header{} + header.Add("Content-Type", "application/zip") + request := &http.Request{ + URL: url, + Header: header, + } serviceDescription := "Deploy service" response := utils.HttpDo(request, serviceDescription) if response.StatusCode == 200 { 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 498f5478688..c2798ab8da4 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 @@ -10,9 +10,8 @@ import ( ) func TestDeployCommand(t *testing.T) { - expectedUrl = "http://127.0.0.1:19071/application/v2/tenant/default/prepareandactivate" assert.Equal(t, "\x1b[32mSuccess \n", - executeCommand(t, []string{"deploy", "testdata/application.zip"}), - "vespa deploy src/github.com/vespa/cmd/testdata/application.zip") + executeCommand(t, []string{"deploy", "testdata/application.zip"})) + assert.Equal(t, "http://127.0.0.1:19071/application/v2/tenant/default/prepareandactivate", lastRequest.URL.String()) } 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 174fb2d53f6..934b7863f94 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,27 +10,29 @@ import ( ) func TestStatusConfigServerCommand(t *testing.T) { - expectedUrl = "http://127.0.0.1:19071/ApplicationStatus" assert.Equal(t, "\x1b[32mConfig server at http://127.0.0.1:19071 is ready \n", executeCommand(t, []string{"status", "config-server"}), "vespa status config-server") + assert.Equal(t, "http://127.0.0.1:19071/ApplicationStatus", lastRequest.URL.String()) } func TestStatusContainerCommand(t *testing.T) { - expectedUrl = "http://127.0.0.1:8080/ApplicationStatus" assert.Equal(t, "\x1b[32mContainer at http://127.0.0.1:8080 is ready \n", executeCommand(t, []string{"status", "container"}), "vespa status container") + assert.Equal(t, "http://127.0.0.1:8080/ApplicationStatus", lastRequest.URL.String()) + assert.Equal(t, "\x1b[32mContainer at http://127.0.0.1:8080 is ready \n", executeCommand(t, []string{"status"}), "vespa status (the default)") + assert.Equal(t, "http://127.0.0.1:8080/ApplicationStatus", lastRequest.URL.String()) } func TestStatusErrorResponse(t *testing.T) { - expectedUrl = "Not the actual url so we get an error response" + nextStatus = 500 assert.Equal(t, "\x1b[31mContainer at http://127.0.0.1:8080 is not ready \n\x1b[33mResponse status: \n", executeCommand(t, []string{"status", "container"}), |