forked from remeh/go-rrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_test.go
49 lines (45 loc) · 1003 Bytes
/
update_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 rrd
import (
"strconv"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestUpdate(t *testing.T) {
update := "1499995020:10:0.3"
tests := []struct {
name string
update Update
}{
{"raw", NewUpdateRaw(update)},
{"raw-now", NewUpdateRaw("N:10:0.3")},
{"basic", NewUpdate(time.Unix(1499995020, 0), 10, 0.3)},
{"now", NewUpdateNow(10, 0.3)},
}
now := time.Now()
eParts := strings.Split(update, ":")
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if strings.Contains(tc.name, "now") {
parts := strings.Split(string(tc.update), ":")
if !assert.Equal(t, len(parts), len(eParts)) {
return
}
for i, v := range parts {
if i == 0 {
i, err := strconv.ParseInt(v, 10, 64)
if !assert.NoError(t, err) {
return
}
assert.True(t, i >= now.Unix())
} else {
assert.Equal(t, eParts[i], v)
}
}
} else {
assert.Equal(t, update, string(tc.update))
}
})
}
}