123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package sshcheckreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver"
- import (
- "context"
- "testing"
- "time"
- "github.com/stretchr/testify/require"
- "go.opentelemetry.io/collector/component"
- "go.opentelemetry.io/collector/consumer/consumertest"
- "go.opentelemetry.io/collector/receiver/receivertest"
- "go.opentelemetry.io/collector/receiver/scraperhelper"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver/internal/configssh"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sshcheckreceiver/internal/metadata"
- )
- func TestNewFactory(t *testing.T) {
- if !supportedOS() {
- t.Skip("Skip tests if not running on one of: [linux, darwin, freebsd, openbsd]")
- }
- t.Parallel()
- testCases := []struct {
- desc string
- testFunc func(*testing.T)
- }{
- {
- desc: "creates a new factory with correct type",
- testFunc: func(t *testing.T) {
- factory := NewFactory()
- require.EqualValues(t, metadata.Type, factory.Type())
- },
- },
- {
- desc: "creates a new factory with default config",
- testFunc: func(t *testing.T) {
- factory := NewFactory()
- var expectedCfg component.Config = &Config{
- ScraperControllerSettings: scraperhelper.ScraperControllerSettings{
- CollectionInterval: 10 * time.Second,
- InitialDelay: time.Second,
- },
- SSHClientSettings: configssh.SSHClientSettings{
- Timeout: 10 * time.Second,
- },
- MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
- }
- require.Equal(t, expectedCfg, factory.CreateDefaultConfig())
- },
- },
- {
- desc: "creates a new factory and CreateMetricsReceiver returns no error",
- testFunc: func(t *testing.T) {
- factory := NewFactory()
- cfg := factory.CreateDefaultConfig()
- _, err := factory.CreateMetricsReceiver(
- context.Background(),
- receivertest.NewNopCreateSettings(),
- cfg,
- consumertest.NewNop(),
- )
- require.NoError(t, err)
- },
- },
- {
- desc: "creates a new factory and CreateMetricsReceiver returns error with incorrect config",
- testFunc: func(t *testing.T) {
- factory := NewFactory()
- _, err := factory.CreateMetricsReceiver(
- context.Background(),
- receivertest.NewNopCreateSettings(),
- nil,
- consumertest.NewNop(),
- )
- require.ErrorIs(t, err, errConfigNotSSHCheck)
- },
- },
- }
- for _, tc := range testCases {
- t.Run(tc.desc, tc.testFunc)
- }
- }
- func TestWindowsReceiverUnsupported(t *testing.T) {
- if supportedOS() {
- t.Skip("Skip test if not running windows.")
- }
- factory := NewFactory()
- _, err := factory.CreateMetricsReceiver(
- context.Background(),
- receivertest.NewNopCreateSettings(),
- nil,
- consumertest.NewNop(),
- )
- require.ErrorIs(t, err, errWindowsUnsupported)
- }
|