github.com/observiq/bindplane-agent@v1.51.0/internal/throughputwrapper/log_consumer_test.go (about) 1 // Copyright observIQ, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package throughputwrapper 16 17 import ( 18 "context" 19 "testing" 20 21 "github.com/stretchr/testify/require" 22 "go.opentelemetry.io/collector/consumer/consumertest" 23 "go.opentelemetry.io/collector/pdata/plog" 24 "go.uber.org/zap" 25 ) 26 27 func Test_newLogConsumer(t *testing.T) { 28 nopLogger := zap.NewNop() 29 componentID := "id" 30 baseConsumer := consumertest.NewNop() 31 lConsumer := newLogConsumer(nopLogger, componentID, baseConsumer) 32 33 require.Equal(t, nopLogger, lConsumer.logger) 34 require.Equal(t, baseConsumer, lConsumer.baseConsumer) 35 require.Len(t, lConsumer.mutators, 1) 36 require.Equal(t, &plog.ProtoMarshaler{}, lConsumer.logsSizer) 37 } 38 39 func Test_logConsumer_ConsumeLogs(t *testing.T) { 40 nopLogger := zap.NewNop() 41 componentID := "id" 42 baseConsumer := new(consumertest.LogsSink) 43 lConsumer := newLogConsumer(nopLogger, componentID, baseConsumer) 44 45 ld := plog.NewLogs() 46 ld.ResourceLogs().AppendEmpty().ScopeLogs().AppendEmpty().LogRecords().AppendEmpty() 47 48 err := lConsumer.ConsumeLogs(context.Background(), ld) 49 require.NoError(t, err) 50 51 require.Equal(t, 1, baseConsumer.LogRecordCount()) 52 } 53 54 func Test_logConsumer_Capabilities(t *testing.T) { 55 nopLogger := zap.NewNop() 56 componentID := "id" 57 baseConsumer := consumertest.NewNop() 58 lConsumer := newLogConsumer(nopLogger, componentID, baseConsumer) 59 60 require.Equal(t, baseConsumer.Capabilities(), lConsumer.Capabilities()) 61 }