Skip to content

Commit 02820ee

Browse files
committed
fix: add more UT for syslog processor increase coverage
1 parent e8085c2 commit 02820ee

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

internal/collector/syslogprocessor/processor_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"testing"
1313

14+
"github.com/leodido/go-syslog/v4/rfc3164"
1415
"github.com/stretchr/testify/assert"
1516
"github.com/stretchr/testify/require"
1617
"go.opentelemetry.io/collector/consumer/consumertest"
@@ -205,3 +206,34 @@ func TestSyslogProcessorFailure(t *testing.T) {
205206
})
206207
}
207208
}
209+
210+
func TestExtractIPFromHostname(t *testing.T) {
211+
assert.Equal(t, "127.0.0.1", extractIPFromHostname("127.0.0.1"))
212+
assert.Equal(t, "172.16.0.213", extractIPFromHostname("ip-172-16-0-213"))
213+
assert.Empty(t, extractIPFromHostname("not-an-ip"))
214+
}
215+
216+
func TestSplitAndTrim(t *testing.T) {
217+
assert.Nil(t, splitAndTrim(""))
218+
assert.Nil(t, splitAndTrim("N/A"))
219+
assert.Equal(t, []string{"a", "b"}, splitAndTrim(" a , b "))
220+
}
221+
222+
func TestBuildSignatures(t *testing.T) {
223+
ids := []string{"1", "2"}
224+
names := []string{"buf1", "buf2"}
225+
sigs := buildSignatures(ids, names, "mask", "off", "len")
226+
assert.Len(t, sigs, 2)
227+
assert.Equal(t, "1", sigs[0].ID)
228+
assert.Equal(t, "buf1", sigs[0].Buffer)
229+
assert.Equal(t, "mask", sigs[0].BlockingMask)
230+
}
231+
232+
func TestSetSyslogAttributesNilFields(t *testing.T) {
233+
lr := plog.NewLogRecord()
234+
m := &rfc3164.SyslogMessage{}
235+
p := newSyslogProcessor(&consumertest.LogsSink{}, processortest.NewNopSettings(processortest.NopType))
236+
p.setSyslogAttributes(lr, m)
237+
attrs := lr.Attributes()
238+
assert.Equal(t, 0, attrs.Len())
239+
}

0 commit comments

Comments
 (0)