add links test for projects last page

This commit is contained in:
Austin 2019-10-30 16:42:11 -07:00
parent a6cb2bed2f
commit 094bccbd77
1 changed files with 23 additions and 0 deletions

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()