Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #699 from jorgevgut/pagerfix
Browse files Browse the repository at this point in the history
ciao-controller: api: Set 'limit' value properly for instances

Fixes: #698
  • Loading branch information
rbradford authored Oct 20, 2016
2 parents 4222f54 + 447b97a commit cf9780c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
22 changes: 16 additions & 6 deletions openstack/compute/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,22 @@ func pagerQueryParse(r *http.Request) (int, int, string) {
// we only support marker and offset for now.
if values["marker"] != nil {
marker = values["marker"][0]
} else if values["offset"] != nil {
o, err := strconv.ParseInt(values["offset"][0], 10, 32)
if err != nil {
offset = 0
} else {
offset = (int)(o)
} else {
if values["offset"] != nil {
o, err := strconv.ParseInt(values["offset"][0], 10, 32)
if err != nil {
offset = 0
} else {
offset = (int)(o)
}
}
if values["limit"] != nil {
l, err := strconv.ParseInt(values["limit"][0], 10, 32)
if err != nil {
limit = 0
} else {
limit = (int)(l)
}
}
}

Expand Down
23 changes: 23 additions & 0 deletions openstack/compute/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ var tests = []test{
http.StatusAccepted,
`{"server":{"id":"validServerID","name":"new-server-test","imageRef":"http://glance.openstack.example.com/images/70a599e0-31e7-49b7-b260-868f441e862b","flavorRef":"http://openstack.example.com/flavors/1","max_count":0,"min_count":0}}`,
},
{
"GET",
"/v2.1/{tenant}/servers/detail?limit=1&offset=1",
ListServersDetails,
"",
http.StatusOK,
`{"total_servers":1,"servers":[]}`,
},
{
"GET",
"/v2.1/{tenant}/servers/detail",
Expand Down Expand Up @@ -274,3 +282,18 @@ func TestRoutes(t *testing.T) {
t.Fatalf("No routes returned")
}
}

func TestPager(t *testing.T) {
req, err := http.NewRequest("GET", "/v2.1/{tenant}/servers/detail?limit=2&offset=2", bytes.NewBuffer([]byte("")))

if err != nil {
t.Fatal(err)
}
limit, offset, _ := pagerQueryParse(req)
if limit != 2 {
t.Fatalf("Invalid limit registered")
}
if offset != 2 {
t.Fatalf("Invalid offset registered")
}
}

0 comments on commit cf9780c

Please sign in to comment.