HTTP API Client: Prolong access to worker 75/181675/9
authorMaciej Wereski <m.wereski@partner.samsung.com>
Fri, 10 Nov 2017 14:16:55 +0000 (15:16 +0100)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Tue, 10 Jul 2018 08:01:25 +0000 (10:01 +0200)
Change-Id: Icd4ad6dfbdd226a3c6a11bb420488299465bd716
Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
http/client/client.go
http/client/client_test.go

index 26b16dd..9419c83 100644 (file)
@@ -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
index 94b4ca1..51d98a0 100644 (file)
@@ -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) {