Skip to content

Commit

Permalink
meta structs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddymko committed Jun 29, 2020
1 parent f649b70 commit ca99de4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions meta.go
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"`
}
36 changes: 36 additions & 0 deletions meta_test.go
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")
}
}

0 comments on commit ca99de4

Please sign in to comment.