-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhttp_test.go
49 lines (40 loc) · 901 Bytes
/
http_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
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"testing"
"github.com/messagebird/pushprom/delta"
"github.com/messagebird/pushprom/metrics"
"github.com/stretchr/testify/assert"
)
func TestHTTP(t *testing.T) {
delta := &delta.Delta{
Type: delta.GAUGE,
Method: "set",
Name: "tree_size",
Help: "the size in meters of the tree",
Value: 8.2,
}
out, _ := json.Marshal(delta)
buf := bytes.NewBuffer(out)
ts := httptest.NewServer(http.Handler(httpHandler{
}))
defer ts.Close()
res, err := http.Post(ts.URL, "application/json", buf)
if err != nil {
log.Fatal(err)
}
_, err = ioutil.ReadAll(res.Body)
res.Body.Close()
assert.Nil(t, err)
ms, err := metrics.Fetch()
assert.Nil(t, err)
result, err := metrics.Read(ms, delta.Name, delta.Labels)
if assert.Nil(t, err) {
assert.Equal(t, delta.Value, result)
}
}