Skip to content

Commit 101d371

Browse files
committed
output: add decoder_test.go
Signed-off-by: Takahiro YAMASHITA <[email protected]>
1 parent e125cab commit 101d371

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

output/decoder_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Fluent Bit Go!
2+
// ==============
3+
// Copyright (C) 2015-2017 Treasure Data Inc.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
//
17+
18+
package output
19+
20+
import (
21+
"reflect"
22+
"testing"
23+
"unsafe"
24+
)
25+
26+
// dummyRecord should be byte Array, not Slice to be able to Cast c array.
27+
var dummyRecord [29]byte = [29]byte{0x92, /* fix array 2 */
28+
0xd7, 0x00, 0x5e, 0xa9, 0x17, 0xe0, 0x00, 0x00, 0x00, 0x00, /* 2020/04/29 06:00:00*/
29+
0x82, /* fix map 2*/
30+
0xa7, 0x63, 0x6f, 0x6e, 0x70, 0x61, 0x63, 0x74, /* fix str 7 "compact" */
31+
0xc3, /* true */
32+
0xa6, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, /* fix str 6 "schema" */
33+
0x01, /* fix int 1 */
34+
}
35+
36+
func TestGetRecord(t *testing.T) {
37+
dec := NewDecoder(unsafe.Pointer(&dummyRecord), len(dummyRecord))
38+
if dec == nil {
39+
t.Fatal("dec is nil")
40+
}
41+
42+
ret, timestamp, record := GetRecord(dec)
43+
if ret < 0 {
44+
t.Fatal("ret is negative")
45+
}
46+
47+
// test timestamp
48+
ts, ok := timestamp.(FLBTime)
49+
if !ok {
50+
t.Fatalf("cast error. Type is %s", reflect.TypeOf(timestamp))
51+
}
52+
53+
if ts.Unix() != int64(0x5ea917e0) {
54+
t.Errorf("ts.Unix() error. given %d", ts.Unix())
55+
}
56+
57+
// test record
58+
v, ok := record["schema"].(int64)
59+
if !ok {
60+
t.Fatalf("cast error. Type is %s", reflect.TypeOf(record["schema"]))
61+
}
62+
if v != 1 {
63+
t.Errorf(`record["schema"] is not 1 %d`, v)
64+
}
65+
}

0 commit comments

Comments
 (0)