diff options
author | Maciej Wereski <m.wereski@partner.samsung.com> | 2017-11-10 15:16:55 +0100 |
---|---|---|
committer | Maciej Wereski <m.wereski@partner.samsung.com> | 2018-07-10 10:01:25 +0200 |
commit | 5b13c89c9619fd6f06d73c6dc568346e64242515 (patch) | |
tree | 9632ae8a19080e2ba5c9ee8bdc34b1cf04c1c8d2 | |
parent | 7b126a9c23d106708f2b9ee5cb183b118f5f5990 (diff) | |
download | boruta-5b13c89c9619fd6f06d73c6dc568346e64242515.tar.gz boruta-5b13c89c9619fd6f06d73c6dc568346e64242515.tar.bz2 boruta-5b13c89c9619fd6f06d73c6dc568346e64242515.zip |
HTTP API Client: Prolong access to worker
Change-Id: Icd4ad6dfbdd226a3c6a11bb420488299465bd716
Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
-rw-r--r-- | http/client/client.go | 7 | ||||
-rw-r--r-- | 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) { |