forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry_test.go
43 lines (32 loc) · 1.23 KB
/
entry_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
package binary
import (
"testing"
"time"
"github.com/influxdata/telegraf/internal"
"github.com/stretchr/testify/require"
)
func TestEntryExtract(t *testing.T) {
testdata := []byte{0x01, 0x02, 0x03, 0x04}
e := &Entry{Type: "uint64"}
_, _, err := e.extract(testdata, 0)
require.EqualError(t, err, `unexpected entry: &{ uint64 0 false [] <nil>}`)
}
func TestEntryConvertType(t *testing.T) {
testdata := []byte{0x01, 0x02, 0x03, 0x04}
e := &Entry{Type: "garbage"}
_, err := e.convertType(testdata, internal.HostEndianess)
require.EqualError(t, err, `cannot handle type "garbage"`)
}
func TestEntryConvertTimeType(t *testing.T) {
testdata := []byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}
e := &Entry{Type: "unix_ns", location: time.UTC}
_, err := e.convertTimeType(testdata, internal.HostEndianess)
require.EqualError(t, err, `too many bytes 9 vs 8`)
}
func TestConvertNumericType(t *testing.T) {
testdata := []byte{0x01, 0x02, 0x03, 0x04}
_, err := convertNumericType(testdata, "garbage", internal.HostEndianess)
require.EqualError(t, err, `cannot determine length for type "garbage"`)
_, err = convertNumericType(testdata, "uint8", internal.HostEndianess)
require.EqualError(t, err, `too many bytes 4 vs 1`)
}