forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
127 lines (116 loc) · 2.64 KB
/
server_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http:https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package fluentforwardreceiver
import (
"bufio"
"bytes"
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/tinylib/msgp/msgp"
)
func TestDetermineNextEventMode(t *testing.T) {
cases := []struct {
name string
event func() []byte
expectedMode EventMode
expectedError error
}{
{
"basic",
func() []byte {
var b []byte
b = msgp.AppendArrayHeader(b, 3)
b = msgp.AppendString(b, "my-tag")
b = msgp.AppendInt(b, 5000)
return b
},
MessageMode,
nil,
},
{
"str8-tag",
func() []byte {
var b []byte
b = msgp.AppendArrayHeader(b, 3)
b = msgp.AppendString(b, strings.Repeat("a", 128))
b = msgp.AppendInt(b, 5000)
return b
},
MessageMode,
nil,
},
{
"str16-tag",
func() []byte {
var b []byte
b = msgp.AppendArrayHeader(b, 3)
b = msgp.AppendString(b, strings.Repeat("a", 1024))
b = msgp.AppendInt(b, 5000)
return b
},
MessageMode,
nil,
},
{
"str32-tag",
func() []byte {
var b []byte
b = msgp.AppendArrayHeader(b, 3)
b = msgp.AppendString(b, strings.Repeat("a", 66000))
b = msgp.AppendInt(b, 5000)
return b
},
MessageMode,
nil,
},
{
"non-string-tag",
func() []byte {
var b []byte
b = msgp.AppendArrayHeader(b, 3)
b = msgp.AppendInt(b, 10)
b = msgp.AppendInt(b, 5000)
return b
},
UnknownMode,
errors.New("malformed tag field"),
},
{
"float-second-elm",
func() []byte {
var b []byte
b = msgp.AppendArrayHeader(b, 3)
b = msgp.AppendString(b, "my-tag")
b = msgp.AppendFloat64(b, 5000.0)
return b
},
UnknownMode,
errors.New("unable to determine next event mode for type float64"),
},
}
for i := range cases {
c := cases[i]
t.Run(c.name, func(t *testing.T) {
peeker := bufio.NewReaderSize(bytes.NewReader(c.event()), 1024*100)
mode, err := DetermineNextEventMode(peeker)
if c.expectedError != nil {
require.Equal(t, c.expectedError, err)
} else {
require.Equal(t, c.expectedMode, mode)
}
})
}
}