forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory_test.go
60 lines (49 loc) · 1.75 KB
/
factory_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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package mongodbatlasreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver"
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configtls"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver/receivertest"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mongodbatlasreceiver/internal/metadata"
)
func TestType(t *testing.T) {
factory := NewFactory()
ft := factory.Type()
require.EqualValues(t, metadata.Type, ft)
}
func TestBadAlertsReceiver(t *testing.T) {
conf := createDefaultConfig()
cfg := conf.(*Config)
cfg.Alerts.Enabled = true
cfg.Alerts.TLS = &configtls.ServerConfig{
ClientCAFile: "/not/a/file",
}
params := receivertest.NewNopCreateSettings()
_, err := createCombinedLogReceiver(context.Background(), params, cfg, consumertest.NewNop())
require.Error(t, err)
require.ErrorContains(t, err, "unable to create a MongoDB Atlas Alerts Receiver")
}
func TestBadStorageExtension(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.StorageID = &component.ID{}
cfg.Events = &EventsConfig{
Projects: []*ProjectConfig{
{
Name: testProjectName,
},
},
PollInterval: time.Minute,
}
params := receivertest.NewNopCreateSettings()
lr, err := createCombinedLogReceiver(context.Background(), params, cfg, consumertest.NewNop())
require.NoError(t, err)
err = lr.Start(context.Background(), componenttest.NewNopHost())
require.ErrorContains(t, err, "failed to get storage client")
}