-
Notifications
You must be signed in to change notification settings - Fork 3
/
exporter_test.go
83 lines (65 loc) · 2.02 KB
/
exporter_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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package fluentforwardexporter // import "github.com/r0mdau/fluentforwardexporter"
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"
)
func TestNewExporter(t *testing.T) {
config := &Config{
TCPClientSettings: TCPClientSettings{
Endpoint: validEndpoint,
ConnectionTimeout: time.Second * 30,
},
}
// Create a new instance of the component.TelemetrySettings struct with a mock logger
logger := zap.NewNop()
settings := component.TelemetrySettings{
Logger: logger,
}
exporter := newExporter(config, settings)
assert.Equal(t, config, exporter.config)
assert.Equal(t, logger, exporter.settings.Logger)
}
func TestStart(t *testing.T) {
config := &Config{
TCPClientSettings: TCPClientSettings{
Endpoint: validEndpoint,
ConnectionTimeout: time.Second * 30,
},
}
logger := zap.NewNop()
settings := component.TelemetrySettings{
Logger: logger,
}
exporter := newExporter(config, settings)
err := exporter.start(context.Background(), nil)
assert.NoError(t, err)
assert.NotNil(t, exporter.client)
}
func TestStartInvalidEndpointErrorLog(t *testing.T) {
observedZapCore, observedLogs := observer.New(zap.InfoLevel)
observedLogger := zap.New(observedZapCore)
config := &Config{
TCPClientSettings: TCPClientSettings{
Endpoint: "invalidEndpoint",
ConnectionTimeout: time.Second * 30,
},
}
settings := component.TelemetrySettings{
Logger: observedLogger,
}
exporter := newExporter(config, settings)
err := exporter.start(context.Background(), nil)
assert.NoError(t, err)
assert.NotNil(t, exporter.client)
require.Equal(t, 2, observedLogs.Len())
assert.Equal(t, "Creating the Fluent Forward exporter", observedLogs.All()[0].Message)
assert.Equal(t, "Failed to connect to the endpoint invalidEndpoint", observedLogs.All()[1].Message)
}