forked from SparkPost/gosparkpost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
del_metrics_test.go
62 lines (55 loc) · 1.45 KB
/
del_metrics_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
package gosparkpost_test
import (
"fmt"
"net/http"
"testing"
sp "github.com/SparkPost/gosparkpost"
)
// The "links" section is snipped for brevity
var delMetricsBaseNoArgs string = `{
"errors": [
{
"message": "from is required",
"param": "from"
},
{
"message": "from must be in the format YYYY-MM-DDTHH:MM",
"param": "from"
},
{
"message": "from must be before to",
"param": "from"
}
],
"links": [
{
"href": "/api/v1/metrics/deliverability",
"method": "GET",
"rel": "deliverability"
},
{
"href": "/api/v1/metrics/deliverability/watched-domain",
"method": "GET",
"rel": "watched-domain"
}
]
}`
func TestMetrics_Get_noArgsError(t *testing.T) {
testSetup(t)
defer testTeardown()
path := fmt.Sprintf(sp.MetricsPathFormat, testClient.Config.ApiVersion)
testMux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.Header().Set("Content-Type", "application/json; charset=utf8")
w.WriteHeader(http.StatusOK)
w.Write([]byte(delMetricsBaseNoArgs))
})
m := &sp.Metrics{}
res, err := testClient.QueryMetrics(m)
if err != nil {
testFailVerbose(t, res, "Metrics GET returned error: %+v", err)
}
if len(m.Errors) != 3 {
testFailVerbose(t, res, "Expected 3 errors, got %d", len(m.Errors))
}
}