// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 package awss3exporter import ( "context" "testing" "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/pdata/plog" "go.uber.org/zap" ) var testLogs = []byte(`{"resourceLogs":[{"resource":{"attributes":[{"key":"_sourceCategory","value":{"stringValue":"logfile"}},{"key":"_sourceHost","value":{"stringValue":"host"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"observedTimeUnixNano":"1654257420681895000","body":{"stringValue":"2022-06-03 13:57:00.62739 +0200 CEST m=+14.018296742 log entry14"},"attributes":[{"key":"log.file.path_resolved","value":{"stringValue":"logwriter/data.log"}}],"traceId":"","spanId":""}]}],"schemaUrl":"https://opentelemetry.io/schemas/1.6.1"}]}`) type TestWriter struct { t *testing.T } func (testWriter *TestWriter) writeBuffer(_ context.Context, buf []byte, _ *Config, _ string, _ string) error { assert.Equal(testWriter.t, testLogs, buf) return nil } func getTestLogs(tb testing.TB) plog.Logs { logsMarshaler := plog.JSONUnmarshaler{} logs, err := logsMarshaler.UnmarshalLogs(testLogs) assert.NoError(tb, err, "Can't unmarshal testing logs data -> %s", err) return logs } func getLogExporter(t *testing.T) *s3Exporter { marshaler, _ := newMarshaler("otlp_json", zap.NewNop()) exporter := &s3Exporter{ config: createDefaultConfig().(*Config), dataWriter: &TestWriter{t}, logger: zap.NewNop(), marshaler: marshaler, } return exporter } func TestLog(t *testing.T) { logs := getTestLogs(t) exporter := getLogExporter(t) assert.NoError(t, exporter.ConsumeLogs(context.Background(), logs)) }