|
| 1 | +// Copyright 2020 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 | + |
| 15 | +package lightstepexporter |
| 16 | + |
| 17 | +import ( |
| 18 | + "path" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/open-telemetry/opentelemetry-collector/config" |
| 22 | + "github.com/open-telemetry/opentelemetry-collector/config/configcheck" |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | + "github.com/stretchr/testify/require" |
| 25 | + "go.uber.org/zap" |
| 26 | +) |
| 27 | + |
| 28 | +func TestCreateDefaultConfig(t *testing.T) { |
| 29 | + factory := Factory{} |
| 30 | + cfg := factory.CreateDefaultConfig() |
| 31 | + assert.NotNil(t, cfg, "failed to create default config") |
| 32 | + assert.NoError(t, configcheck.ValidateConfig(cfg)) |
| 33 | +} |
| 34 | + |
| 35 | +func TestCreateTraceExporter(t *testing.T) { |
| 36 | + logger := zap.NewNop() |
| 37 | + |
| 38 | + factories, err := config.ExampleComponents() |
| 39 | + require.NoError(t, err) |
| 40 | + factory := Factory{} |
| 41 | + factories.Exporters[typeStr] = &factory |
| 42 | + cfg, err := config.LoadConfigFile( |
| 43 | + t, path.Join(".", "testdata", "config.yaml"), factories, |
| 44 | + ) |
| 45 | + require.NoError(t, err) |
| 46 | + |
| 47 | + exporter, err := factory.CreateTraceExporter(logger, cfg.Exporters["lightstep/customname"]) |
| 48 | + assert.Nil(t, err) |
| 49 | + assert.NotNil(t, exporter) |
| 50 | +} |
| 51 | + |
| 52 | +func TestCreateMetricsExporter(t *testing.T) { |
| 53 | + logger := zap.NewNop() |
| 54 | + |
| 55 | + factories, err := config.ExampleComponents() |
| 56 | + require.NoError(t, err) |
| 57 | + factory := Factory{} |
| 58 | + factories.Exporters[typeStr] = &factory |
| 59 | + cfg, err := config.LoadConfigFile( |
| 60 | + t, path.Join(".", "testdata", "config.yaml"), factories, |
| 61 | + ) |
| 62 | + require.NoError(t, err) |
| 63 | + |
| 64 | + exporter, err := factory.CreateMetricsExporter(logger, cfg.Exporters["lightstep/customname"]) |
| 65 | + assert.NotNil(t, err) |
| 66 | + assert.Nil(t, exporter) |
| 67 | +} |
0 commit comments