HTTP API Client: Get request information 72/181672/7
authorMaciej Wereski <m.wereski@partner.samsung.com>
Fri, 10 Nov 2017 12:57:53 +0000 (13:57 +0100)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Thu, 5 Jul 2018 07:42:18 +0000 (09:42 +0200)
Change-Id: Ic2b18ea346c78b50cf0f6754848a31feb753c253
Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
http/client/client.go
http/client/client_test.go

index 45f1870..b218473 100644 (file)
@@ -206,9 +206,15 @@ func (client *BorutaClient) UpdateRequest(reqInfo *boruta.ReqInfo) error {
 }
 
 // GetRequestInfo queries Boruta server for details about given request ID.
-func (client *BorutaClient) GetRequestInfo(reqID boruta.ReqID) (*boruta.ReqInfo,
-       error) {
-       return nil, util.ErrNotImplemented
+func (client *BorutaClient) GetRequestInfo(reqID boruta.ReqID) (boruta.ReqInfo, error) {
+       var reqInfo boruta.ReqInfo
+       path := client.url + "reqs/" + strconv.Itoa(int(reqID))
+       resp, err := http.Get(path)
+       if err != nil {
+               return reqInfo, err
+       }
+       err = processResponse(resp, &reqInfo)
+       return reqInfo, err
 }
 
 // ListRequests queries Boruta server for list of requests that match given
index 6e4970c..2b680e2 100644 (file)
@@ -460,12 +460,48 @@ func TestUpdateRequest(t *testing.T) {
 }
 
 func TestGetRequestInfo(t *testing.T) {
-       assert, client := initTest(t, "")
-       assert.NotNil(client)
+       prefix := "req-info"
+       path := "/api/v1/reqs/"
 
-       reqInfo, err := client.GetRequestInfo(ReqID(0))
-       assert.Nil(reqInfo)
-       assert.Equal(util.ErrNotImplemented, err)
+       tests := []*testCase{
+               &testCase{
+                       // valid request
+                       name:        prefix,
+                       path:        path + "1",
+                       contentType: contentJSON,
+                       status:      http.StatusOK,
+               },
+               &testCase{
+                       // missing request
+                       name:        prefix + "-missing",
+                       path:        path + "2",
+                       contentType: contentJSON,
+                       status:      http.StatusNotFound,
+               },
+       }
+
+       srv := prepareServer(http.MethodGet, tests)
+       defer srv.Close()
+       assert, client := initTest(t, srv.URL)
+
+       // valid
+       req := req
+       req.ID = ReqID(1)
+       req.State = WAIT
+       reqInfo, err := client.GetRequestInfo(ReqID(1))
+       assert.Nil(err)
+       assert.Equal(req, reqInfo)
+
+       // missing
+       reqInfo, err = client.GetRequestInfo(ReqID(2))
+       assert.Zero(reqInfo)
+       assert.Equal(errReqNotFound, err)
+
+       // http.Get failure
+       client.url = "http://nosuchaddress.fail"
+       reqInfo, err = client.GetRequestInfo(ReqID(1))
+       assert.Zero(reqInfo)
+       assert.NotNil(err)
 }
 
 func TestListRequests(t *testing.T) {