forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
marshaler_test.go
73 lines (57 loc) · 1.85 KB
/
marshaler_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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package rabbitmqexporter
import (
"context"
"testing"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
)
func TestMarshalUsingEncodingExtension(t *testing.T) {
host := mockHostWithEncodings{}
extension := mockEncodingExtension{}
extensionMap := make(map[component.ID]component.Component)
extensionMap[encodingComponentID] = &extension
host.On("GetExtensions").Return(extensionMap)
m, err := newMarshaler(&encodingComponentID, &host)
require.NotNil(t, m)
require.NoError(t, err)
require.Equal(t, m.logsMarshaler, &extension)
require.Equal(t, m.metricsMarshaler, &extension)
require.Equal(t, m.tracesMarshaler, &extension)
}
type mockHostWithEncodings struct {
mock.Mock
}
type mockEncodingExtension struct {
mock.Mock
}
func (h *mockHostWithEncodings) GetFactory(component.Kind, component.Type) component.Factory {
return nil
}
func (h *mockHostWithEncodings) GetExporters() map[component.DataType]map[component.ID]component.Component {
return nil
}
func (h *mockHostWithEncodings) GetExtensions() map[component.ID]component.Component {
args := h.Called()
return args.Get(0).(map[component.ID]component.Component)
}
func (m *mockEncodingExtension) MarshalLogs(plog.Logs) ([]byte, error) {
return nil, nil
}
func (m *mockEncodingExtension) MarshalTraces(ptrace.Traces) ([]byte, error) {
return nil, nil
}
func (m *mockEncodingExtension) MarshalMetrics(pmetric.Metrics) ([]byte, error) {
return nil, nil
}
func (m *mockEncodingExtension) Start(context.Context, component.Host) error {
return nil
}
func (m *mockEncodingExtension) Shutdown(context.Context) error {
return nil
}