summaryrefslogtreecommitdiff
path: root/requests
diff options
context:
space:
mode:
authorMaciej Wereski <m.wereski@partner.samsung.com>2017-09-29 11:14:22 +0200
committerMaciej Wereski <m.wereski@partner.samsung.com>2018-06-05 11:26:40 +0200
commit1966d770ebbcceaf4ddc90fcaae107904589c14f (patch)
tree00a037b17b3699087a12e777f62398e821d331d1 /requests
parent27b25c8c40a0a8dedaf01115b9f1beef25a3a1b2 (diff)
downloadboruta-1966d770ebbcceaf4ddc90fcaae107904589c14f.tar.gz
boruta-1966d770ebbcceaf4ddc90fcaae107904589c14f.tar.bz2
boruta-1966d770ebbcceaf4ddc90fcaae107904589c14f.zip
HTTP API: Implement listing and filtering requests
Change-Id: I27f8d037978ef0f0f60ea5c7ee406f8459a90796 Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
Diffstat (limited to 'requests')
-rw-r--r--requests/requests.go12
-rw-r--r--requests/requests_test.go7
2 files changed, 16 insertions, 3 deletions
diff --git a/requests/requests.go b/requests/requests.go
index c343f22..952c55a 100644
--- a/requests/requests.go
+++ b/requests/requests.go
@@ -18,6 +18,8 @@
package requests
import (
+ "reflect"
+ "sort"
"sync"
"time"
@@ -257,16 +259,20 @@ func (reqs *ReqsCollection) GetRequestInfo(reqID ReqID) (ReqInfo, error) {
}
// ListRequests is part of implementation of Requests interface. It returns slice
-// of ReqInfo that matches ListFilter.
+// of ReqInfo that matches ListFilter. Returned slice is sorted by request ids.
func (reqs *ReqsCollection) ListRequests(filter ListFilter) ([]ReqInfo, error) {
reqs.mutex.RLock()
- defer reqs.mutex.RUnlock()
res := make([]ReqInfo, 0, len(reqs.requests))
for _, req := range reqs.requests {
- if filter == nil || filter.Match(req) {
+ if filter == nil || reflect.ValueOf(filter).IsNil() ||
+ filter.Match(req) {
res = append(res, *req)
}
}
+ reqs.mutex.RUnlock()
+ // TODO(mwereski): HTTP backend needs this to be sorted. This isn't best
+ // place to do it, rethink that when DB backend is implemented.
+ sort.Slice(res, func(i, j int) bool { return res[i].ID < res[j].ID })
return res, nil
}
diff --git a/requests/requests_test.go b/requests/requests_test.go
index 2226ffb..3dcb708 100644
--- a/requests/requests_test.go
+++ b/requests/requests_test.go
@@ -471,9 +471,16 @@ func TestListRequests(t *testing.T) {
}
// Nil filter should return all requests.
+
+ // Nil interface.
resp, err := rqueue.ListRequests(nil)
assert.Nil(err)
checkReqs(reqs, resp)
+ var flt *reqFilter
+ // Concrete type is nil but interface isn't nil.
+ resp, err = rqueue.ListRequests(flt)
+ assert.Nil(err)
+ checkReqs(reqs, resp)
}
func TestAcquireWorker(t *testing.T) {