From: Maciej Wereski Date: Fri, 10 Nov 2017 12:57:53 +0000 (+0100) Subject: HTTP API Client: Get request information X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cfa63e7dbd4f22aa5d20460ec4b01d1d3f7739ea;p=tools%2Fboruta.git HTTP API Client: Get request information Change-Id: Ic2b18ea346c78b50cf0f6754848a31feb753c253 Signed-off-by: Maciej Wereski --- diff --git a/http/client/client.go b/http/client/client.go index 45f1870..b218473 100644 --- a/http/client/client.go +++ b/http/client/client.go @@ -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 diff --git a/http/client/client_test.go b/http/client/client_test.go index 6e4970c..2b680e2 100644 --- a/http/client/client_test.go +++ b/http/client/client_test.go @@ -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) {