// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 package opensearchexporter import ( "context" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/exporter/exportertest" ) func TestCreateDefaultConfig(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } func TestFactory_CreateMetricsExporter_Fail(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() params := exportertest.NewNopCreateSettings() _, err := factory.CreateMetricsExporter(context.Background(), params, cfg) require.Error(t, err, "expected an error when creating a metrics exporter") } func TestFactory_CreateTracesExporter_Fail(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() params := exportertest.NewNopCreateSettings() _, err := factory.CreateTracesExporter(context.Background(), params, cfg) require.Error(t, err, "expected an error when creating a traces exporter") } func TestFactory_CreateLogsExporter_Fail(t *testing.T) { factory := NewFactory() cfg := factory.CreateDefaultConfig() params := exportertest.NewNopCreateSettings() _, err := factory.CreateLogsExporter(context.Background(), params, cfg) require.Error(t, err, "expected an error when creating a logs exporter") } func TestFactory_CreateTracesExporter(t *testing.T) { factory := NewFactory() cfg := withDefaultConfig(func(cfg *Config) { cfg.Endpoint = "https://opensearch.example.com:9200" }) params := exportertest.NewNopCreateSettings() exporter, err := factory.CreateTracesExporter(context.Background(), params, cfg) require.NoError(t, err) require.NotNil(t, exporter) require.NoError(t, exporter.Shutdown(context.TODO())) } func TestFactory_CreateLogsExporter(t *testing.T) { factory := NewFactory() cfg := withDefaultConfig(func(cfg *Config) { cfg.Endpoint = "https://opensearch.example.com:9200" }) params := exportertest.NewNopCreateSettings() exporter, err := factory.CreateLogsExporter(context.Background(), params, cfg) require.NoError(t, err) require.NotNil(t, exporter) require.NoError(t, exporter.Shutdown(context.TODO())) }