-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod_test.go
68 lines (57 loc) · 1.4 KB
/
mod_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package dyspatch_test
import (
"bytes"
"fmt"
"io"
"os"
"testing"
"github.com/antihax/optional"
"github.com/getdyspatch/dyspatch-golang"
"golang.org/x/net/context"
)
const version = "application/vnd.dyspatch.2020.04+json"
func bodyToString(body io.ReadCloser) string {
buf := new(bytes.Buffer)
buf.ReadFrom(body)
return buf.String()
}
func TestMain(t *testing.T) {
cfg := dyspatch.NewConfiguration()
auth := context.WithValue(context.Background(), dyspatch.ContextAPIKey, dyspatch.APIKey{
Key: os.Getenv("DYSPATCH_API_KEY"),
Prefix: "Bearer",
})
client := dyspatch.NewAPIClient(cfg)
client.TemplatesApi.GetTemplates(auth, version, nil)
templates, _, err := client.TemplatesApi.GetTemplates(auth, version, nil)
if err != nil {
t.Fatal(err)
}
// Print out Templates
for _, template := range templates.Data {
fmt.Println(template.Name)
}
// Get Drafts
drafts, _, err := client.DraftsApi.GetDrafts(auth, version, nil)
if err != nil {
t.Fatal(err)
}
fmt.Printf("%v\n", drafts)
for _, draft := range drafts.Data {
fmt.Printf("%v\n", draft)
}
// Page through drafts
cursorVal := ""
keepPaging := true
for {
drafts, _, _ := client.DraftsApi.GetDrafts(auth, version, &dyspatch.GetDraftsOpts{
Cursor: optional.NewString(cursorVal),
})
cursorVal = drafts.Cursor.Next
keepPaging = drafts.Cursor.HasMore
fmt.Printf("%v\n", drafts.Cursor.Next)
if !keepPaging {
break
}
}
}