From 5b13c89c9619fd6f06d73c6dc568346e64242515 Mon Sep 17 00:00:00 2001 From: Maciej Wereski Date: Fri, 10 Nov 2017 15:16:55 +0100 Subject: [PATCH] HTTP API Client: Prolong access to worker Change-Id: Icd4ad6dfbdd226a3c6a11bb420488299465bd716 Signed-off-by: Maciej Wereski --- http/client/client.go | 7 ++++++- http/client/client_test.go | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/http/client/client.go b/http/client/client.go index 26b16dd..9419c83 100644 --- a/http/client/client.go +++ b/http/client/client.go @@ -269,7 +269,12 @@ func (client *BorutaClient) AcquireWorker(reqID boruta.ReqID) (boruta.AccessInfo // If not called, Boruta server will terminate the tunnel when ReqInfo.Job.Timeout // passes, and change state of request to CLOSED. func (client *BorutaClient) ProlongAccess(reqID boruta.ReqID) error { - return util.ErrNotImplemented + path := client.url + "reqs/" + strconv.Itoa(int(reqID)) + "/prolong" + resp, err := http.Post(path, "", nil) + if err != nil { + return err + } + return processResponse(resp, nil) } // ListWorkers queries Boruta server for list of workers that are in given groups diff --git a/http/client/client_test.go b/http/client/client_test.go index 94b4ca1..51d98a0 100644 --- a/http/client/client_test.go +++ b/http/client/client_test.go @@ -691,11 +691,39 @@ func TestAcquireWorker(t *testing.T) { } func TestProlongAccess(t *testing.T) { - assert, client := initTest(t, "") - assert.NotNil(client) + prefix := "prolong-access-" + path := "/api/v1/reqs/" - err := client.ProlongAccess(ReqID(0)) - assert.Equal(util.ErrNotImplemented, err) + tests := []*testCase{ + &testCase{ + // valid request + name: prefix + "valid", + path: path + "1/prolong", + contentType: contentJSON, + status: http.StatusNoContent, + }, + &testCase{ + // missing request + name: prefix + "missing", + path: path + "2/prolong", + contentType: contentJSON, + status: http.StatusNotFound, + }, + } + + srv := prepareServer(http.MethodPost, tests) + defer srv.Close() + assert, client := initTest(t, srv.URL) + + // valid + assert.Nil(client.ProlongAccess(ReqID(1))) + + // missing + assert.Equal(errReqNotFound, client.ProlongAccess(ReqID(2))) + + // http.Post failure + client.url = "http://nosuchaddress.fail" + assert.NotNil(client.ProlongAccess(ReqID(1))) } func TestListWorkers(t *testing.T) { -- 2.7.4