-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraphigo_suite_test.go
65 lines (52 loc) · 1.31 KB
/
graphigo_suite_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
package graphigo_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"fmt"
"strconv"
"strings"
"testing"
"time"
"gopkg.in/fgrosse/graphigo.v2"
)
func TestGraphigo(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Graphigo Suite")
}
type connMock struct {
IsClosed bool
SentMetrics []graphigo.Metric
}
func newConnectionMock() *connMock {
return &connMock{
IsClosed: false,
SentMetrics: []graphigo.Metric{},
}
}
func (c *connMock) Write(b []byte) (n int, err error) {
metricLines := strings.Split(string(b), "\n")
if len(metricLines) == 0 {
return 0, fmt.Errorf("No metrics given at all!")
}
for i, line := range metricLines {
if line == "" {
continue
}
metricParts := strings.Split(line, " ")
if len(metricParts) != 3 {
return 0, fmt.Errorf("Invalid metric format given in metric line %d: %q", i, line)
}
newMetric := graphigo.Metric{Name: metricParts[0], Value: metricParts[1]}
timeStamp, err := strconv.ParseInt(metricParts[2], 10, 64)
if err != nil {
return 0, fmt.Errorf("Could not parse metric timestamp %q: %s", metricParts[2], err.Error())
}
newMetric.Timestamp = time.Unix(timeStamp, 0).UTC()
c.SentMetrics = append(c.SentMetrics, newMetric)
}
return len(b), nil
}
func (c *connMock) Close() error {
c.IsClosed = true
return nil
}