Merge pull request #264 from aqche/update_link_islast
Update isLast to check p.Next
This commit is contained in:
commit
b76823c59a
2
links.go
2
links.go
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue