forked from vultr/govultr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package govultr | ||
|
||
// Meta represents the available pagination information | ||
type Meta struct { | ||
Total int `json:"total"` | ||
Links *Links | ||
} | ||
|
||
// Links represent the next/previous cursor in your pagination calls | ||
type Links struct { | ||
Next string `json:"next"` | ||
Prev string `json:"prev"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package govultr | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
) | ||
|
||
var metaBytes = []byte(` | ||
{ | ||
"total": 11, | ||
"links": { | ||
"next": "bmV4dF9fMTMxOTgxNQ==", | ||
"prev": "" | ||
} | ||
} | ||
`) | ||
|
||
func TestMeta(t *testing.T) { | ||
var meta *Meta | ||
|
||
if err := json.Unmarshal(metaBytes, &meta); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if meta.Total != 11 { | ||
t.Fatal("Total did not equal 11") | ||
} | ||
|
||
if meta.Links.Next != "bmV4dF9fMTMxOTgxNQ==" { | ||
t.Fatal("Next cursor did not equal bmV4dF9fMTMxOTgxNQ==") | ||
} | ||
|
||
if meta.Links.Prev != "" { | ||
t.Fatal("Previous cursor was not empty") | ||
} | ||
} |