factory_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package opensearchexporter
  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_CreateMetricsExporter_Fail(t *testing.T) {
  19. factory := NewFactory()
  20. cfg := factory.CreateDefaultConfig()
  21. params := exportertest.NewNopCreateSettings()
  22. _, err := factory.CreateMetricsExporter(context.Background(), params, cfg)
  23. require.Error(t, err, "expected an error when creating a metrics exporter")
  24. }
  25. func TestFactory_CreateTracesExporter_Fail(t *testing.T) {
  26. factory := NewFactory()
  27. cfg := factory.CreateDefaultConfig()
  28. params := exportertest.NewNopCreateSettings()
  29. _, err := factory.CreateTracesExporter(context.Background(), params, cfg)
  30. require.Error(t, err, "expected an error when creating a traces exporter")
  31. }
  32. func TestFactory_CreateLogsExporter_Fail(t *testing.T) {
  33. factory := NewFactory()
  34. cfg := factory.CreateDefaultConfig()
  35. params := exportertest.NewNopCreateSettings()
  36. _, err := factory.CreateLogsExporter(context.Background(), params, cfg)
  37. require.Error(t, err, "expected an error when creating a logs exporter")
  38. }
  39. func TestFactory_CreateTracesExporter(t *testing.T) {
  40. factory := NewFactory()
  41. cfg := withDefaultConfig(func(cfg *Config) {
  42. cfg.Endpoint = "https://opensearch.example.com:9200"
  43. })
  44. params := exportertest.NewNopCreateSettings()
  45. exporter, err := factory.CreateTracesExporter(context.Background(), params, cfg)
  46. require.NoError(t, err)
  47. require.NotNil(t, exporter)
  48. require.NoError(t, exporter.Shutdown(context.TODO()))
  49. }
  50. func TestFactory_CreateLogsExporter(t *testing.T) {
  51. factory := NewFactory()
  52. cfg := withDefaultConfig(func(cfg *Config) {
  53. cfg.Endpoint = "https://opensearch.example.com:9200"
  54. })
  55. params := exportertest.NewNopCreateSettings()
  56. exporter, err := factory.CreateLogsExporter(context.Background(), params, cfg)
  57. require.NoError(t, err)
  58. require.NotNil(t, exporter)
  59. require.NoError(t, exporter.Shutdown(context.TODO()))
  60. }