fluentd_exporter_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package main
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/component/componenttest"
  9. "go.opentelemetry.io/collector/pdata/plog"
  10. "go.opentelemetry.io/collector/pdata/pmetric"
  11. "go.opentelemetry.io/collector/pdata/ptrace"
  12. )
  13. func TestNewNopFactory(t *testing.T) {
  14. factory := NewNopFactory()
  15. require.NotNil(t, factory)
  16. assert.Equal(t, component.Type("nop"), factory.Type())
  17. cfg := factory.CreateDefaultConfig()
  18. assert.Equal(t, &nopConfig{}, cfg)
  19. traces, err := factory.CreateTracesExporter(context.Background(), NewNopCreateSettings(), cfg)
  20. require.NoError(t, err)
  21. assert.NoError(t, traces.Start(context.Background(), componenttest.NewNopHost()))
  22. assert.NoError(t, traces.ConsumeTraces(context.Background(), ptrace.NewTraces()))
  23. assert.NoError(t, traces.Shutdown(context.Background()))
  24. metrics, err := factory.CreateMetricsExporter(context.Background(), NewNopCreateSettings(), cfg)
  25. require.NoError(t, err)
  26. assert.NoError(t, metrics.Start(context.Background(), componenttest.NewNopHost()))
  27. assert.NoError(t, metrics.ConsumeMetrics(context.Background(), pmetric.NewMetrics()))
  28. assert.NoError(t, metrics.Shutdown(context.Background()))
  29. logs, err := factory.CreateLogsExporter(context.Background(), NewNopCreateSettings(), cfg)
  30. require.NoError(t, err)
  31. assert.NoError(t, logs.Start(context.Background(), componenttest.NewNopHost()))
  32. assert.NoError(t, logs.ConsumeLogs(context.Background(), plog.NewLogs()))
  33. assert.NoError(t, logs.Shutdown(context.Background()))
  34. }
  35. func TestNewNopBuilder(t *testing.T) {
  36. builder := NewNopBuilder()
  37. require.NotNil(t, builder)
  38. factory := NewNopFactory()
  39. cfg := factory.CreateDefaultConfig()
  40. set := NewNopCreateSettings()
  41. set.ID = component.NewID(typeStr)
  42. traces, err := factory.CreateTracesExporter(context.Background(), set, cfg)
  43. require.NoError(t, err)
  44. bTraces, err := builder.CreateTraces(context.Background(), set)
  45. require.NoError(t, err)
  46. assert.IsType(t, traces, bTraces)
  47. metrics, err := factory.CreateMetricsExporter(context.Background(), set, cfg)
  48. require.NoError(t, err)
  49. bMetrics, err := builder.CreateMetrics(context.Background(), set)
  50. require.NoError(t, err)
  51. assert.IsType(t, metrics, bMetrics)
  52. logs, err := factory.CreateLogsExporter(context.Background(), set, cfg)
  53. require.NoError(t, err)
  54. bLogs, err := builder.CreateLogs(context.Background(), set)
  55. require.NoError(t, err)
  56. assert.IsType(t, logs, bLogs)
  57. }