Merge pull request #264 from aqche/update_link_islast

Update isLast to check p.Next
This commit is contained in:
Ben Tranter 2019-11-04 11:28:15 -05:00 committed by GitHub
commit b76823c59a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -59,7 +59,7 @@ func (l *Links) IsLastPage() bool {
}
func (p *Pages) isLast() bool {
return p.Last == ""
return p.Next == ""
}
func pageForURL(urlText string) (int, error) {

View File

@ -32,6 +32,15 @@ var (
}
}
}`)
projectsLastPageLinksJSONBlob = []byte(`{
"links": {
"pages": {
"first": "https://api.digitalocean.com/v2/projects?page=1",
"prev": "https://api.digitalocean.com/v2/projects?page=2",
"last": "https://api.digitalocean.com/v2/projects?page=3"
}
}
}`)
missingLinksJSONBlob = []byte(`{ }`)
)
@ -94,6 +103,20 @@ func TestLinks_ParseLast(t *testing.T) {
}
}
func TestLinks_ParseProjectsLast(t *testing.T) {
links := loadLinksJSON(t, projectsLastPageLinksJSONBlob)
_, err := links.CurrentPage()
if err != nil {
t.Fatal(err)
}
r := &Response{Links: &links}
checkCurrentPage(t, r, 3)
if !links.IsLastPage() {
t.Fatalf("expected last page")
}
}
func TestLinks_ParseMissing(t *testing.T) {
links := loadLinksJSON(t, missingLinksJSONBlob)
_, err := links.CurrentPage()