|
| 1 | +// Copyright The OpenTelemetry Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +package datadogexporter |
| 15 | + |
| 16 | +import ( |
| 17 | + "context" |
| 18 | + "path" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/stretchr/testify/assert" |
| 22 | + "github.com/stretchr/testify/require" |
| 23 | + "go.opentelemetry.io/collector/component" |
| 24 | + "go.opentelemetry.io/collector/component/componenttest" |
| 25 | + "go.opentelemetry.io/collector/config/configcheck" |
| 26 | + "go.opentelemetry.io/collector/config/configmodels" |
| 27 | + "go.opentelemetry.io/collector/config/configtest" |
| 28 | + "go.uber.org/zap" |
| 29 | +) |
| 30 | + |
| 31 | +// Test that the factory creates the default configuration |
| 32 | +func TestCreateDefaultConfig(t *testing.T) { |
| 33 | + factory := NewFactory() |
| 34 | + cfg := factory.CreateDefaultConfig() |
| 35 | + |
| 36 | + assert.Equal(t, cfg, &Config{ |
| 37 | + Site: DefaultSite, |
| 38 | + Tags: DefaultTags, |
| 39 | + Mode: DefaultMode, |
| 40 | + }, "failed to create default config") |
| 41 | + |
| 42 | + assert.NoError(t, configcheck.ValidateConfig(cfg)) |
| 43 | +} |
| 44 | + |
| 45 | +func TestCreateAgentMetricsExporter(t *testing.T) { |
| 46 | + logger := zap.NewNop() |
| 47 | + |
| 48 | + factories, err := componenttest.ExampleComponents() |
| 49 | + assert.NoError(t, err) |
| 50 | + |
| 51 | + factory := NewFactory() |
| 52 | + factories.Exporters[configmodels.Type(typeStr)] = factory |
| 53 | + cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) |
| 54 | + |
| 55 | + require.NoError(t, err) |
| 56 | + require.NotNil(t, cfg) |
| 57 | + |
| 58 | + ctx := context.Background() |
| 59 | + exp, err := factory.CreateMetricsExporter( |
| 60 | + ctx, |
| 61 | + component.ExporterCreateParams{Logger: logger}, |
| 62 | + cfg.Exporters["datadog"], |
| 63 | + ) |
| 64 | + assert.Nil(t, err) |
| 65 | + assert.NotNil(t, exp) |
| 66 | +} |
| 67 | + |
| 68 | +func TestCreateAPIMetricsExporter(t *testing.T) { |
| 69 | + logger := zap.NewNop() |
| 70 | + |
| 71 | + factories, err := componenttest.ExampleComponents() |
| 72 | + assert.NoError(t, err) |
| 73 | + |
| 74 | + factory := NewFactory() |
| 75 | + factories.Exporters[configmodels.Type(typeStr)] = factory |
| 76 | + cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) |
| 77 | + |
| 78 | + require.NoError(t, err) |
| 79 | + require.NotNil(t, cfg) |
| 80 | + |
| 81 | + ctx := context.Background() |
| 82 | + exp, err := factory.CreateMetricsExporter( |
| 83 | + ctx, |
| 84 | + component.ExporterCreateParams{Logger: logger}, |
| 85 | + cfg.Exporters["datadog/2"], |
| 86 | + ) |
| 87 | + |
| 88 | + // Not implemented |
| 89 | + assert.NotNil(t, err) |
| 90 | + assert.Nil(t, exp) |
| 91 | +} |
| 92 | + |
| 93 | +func TestCreateAPITraceExporter(t *testing.T) { |
| 94 | + logger := zap.NewNop() |
| 95 | + |
| 96 | + factories, err := componenttest.ExampleComponents() |
| 97 | + assert.NoError(t, err) |
| 98 | + |
| 99 | + factory := NewFactory() |
| 100 | + factories.Exporters[configmodels.Type(typeStr)] = factory |
| 101 | + cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories) |
| 102 | + |
| 103 | + require.NoError(t, err) |
| 104 | + require.NotNil(t, cfg) |
| 105 | + |
| 106 | + ctx := context.Background() |
| 107 | + exp, err := factory.CreateTraceExporter( |
| 108 | + ctx, |
| 109 | + component.ExporterCreateParams{Logger: logger}, |
| 110 | + cfg.Exporters["datadog/2"], |
| 111 | + ) |
| 112 | + |
| 113 | + // Not implemented |
| 114 | + assert.NotNil(t, err) |
| 115 | + assert.Nil(t, exp) |
| 116 | +} |
0 commit comments