-
Notifications
You must be signed in to change notification settings - Fork 143
/
integration_test.go
59 lines (47 loc) · 1.15 KB
/
integration_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
//go:build integration
package mailgun_test
import (
"context"
"encoding/json"
"testing"
"time"
"github.com/mailgun/mailgun-go/v4"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIntegrationMailgunImpl_ListMetrics(t *testing.T) {
mg, err := mailgun.NewMailgunFromEnv()
if err != nil {
require.NoError(t, err)
}
opts := mailgun.MetricsOptions{
End: mailgun.RFC2822Time(time.Now().UTC()),
Duration: "30d",
Pagination: mailgun.MetricsPagination{
Limit: 10,
},
}
iter, err := mg.ListMetrics(opts)
require.NoError(t, err)
// create context to list all pages
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
defer cancel()
for i := 0; i < 2; i++ {
var resp mailgun.MetricsResponse
more := iter.Next(ctx, &resp)
if iter.Err() != nil {
require.NoError(t, err)
}
t.Logf("Page %d: Start: %s; End: %s; Pagination: %+v\n",
i+1, resp.Start, resp.End, resp.Pagination)
assert.GreaterOrEqual(t, len(resp.Items), 1)
for _, item := range resp.Items {
b, _ := json.Marshal(item)
t.Logf("%s\n", b)
}
if !more {
t.Log("no more pages")
break
}
}
}