factory_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package clickhouseexporter
  4. import (
  5. "context"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/component/componenttest"
  10. "go.opentelemetry.io/collector/exporter/exportertest"
  11. )
  12. func TestCreateDefaultConfig(t *testing.T) {
  13. factory := NewFactory()
  14. cfg := factory.CreateDefaultConfig()
  15. assert.NotNil(t, cfg, "failed to create default config")
  16. assert.NoError(t, componenttest.CheckConfigStruct(cfg))
  17. }
  18. func TestFactory_CreateLogsExporter(t *testing.T) {
  19. factory := NewFactory()
  20. cfg := withDefaultConfig(func(cfg *Config) {
  21. cfg.Endpoint = defaultEndpoint
  22. })
  23. params := exportertest.NewNopCreateSettings()
  24. exporter, err := factory.CreateLogsExporter(context.Background(), params, cfg)
  25. require.NoError(t, err)
  26. require.NotNil(t, exporter)
  27. require.NoError(t, exporter.Shutdown(context.TODO()))
  28. }
  29. func TestFactory_CreateTracesExporter(t *testing.T) {
  30. factory := NewFactory()
  31. cfg := withDefaultConfig(func(cfg *Config) {
  32. cfg.Endpoint = defaultEndpoint
  33. })
  34. params := exportertest.NewNopCreateSettings()
  35. exporter, err := factory.CreateTracesExporter(context.Background(), params, cfg)
  36. require.NoError(t, err)
  37. require.NotNil(t, exporter)
  38. require.NoError(t, exporter.Shutdown(context.TODO()))
  39. }
  40. func TestFactory_CreateMetricsExporter(t *testing.T) {
  41. factory := NewFactory()
  42. cfg := withDefaultConfig(func(cfg *Config) {
  43. cfg.Endpoint = defaultEndpoint
  44. })
  45. params := exportertest.NewNopCreateSettings()
  46. exporter, err := factory.CreateMetricsExporter(context.Background(), params, cfg)
  47. require.NoError(t, err)
  48. require.NotNil(t, exporter)
  49. require.NoError(t, exporter.Shutdown(context.TODO()))
  50. }