|
| 1 | +// Copyright (c) 2020 The Jaeger 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 defaults |
| 16 | + |
| 17 | +import ( |
| 18 | + "sort" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/open-telemetry/opentelemetry-collector/config" |
| 22 | + "github.com/open-telemetry/opentelemetry-collector/config/configmodels" |
| 23 | + "github.com/spf13/viper" |
| 24 | + "github.com/stretchr/testify/assert" |
| 25 | + "github.com/stretchr/testify/require" |
| 26 | + "go.uber.org/zap" |
| 27 | + |
| 28 | + "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/cassandra" |
| 29 | + "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/elasticsearch" |
| 30 | + "github.com/jaegertracing/jaeger/cmd/opentelemetry-collector/app/exporter/kafka" |
| 31 | +) |
| 32 | + |
| 33 | +func TestDefaultConfig(t *testing.T) { |
| 34 | + factories := Components(viper.New()) |
| 35 | + tests := []struct { |
| 36 | + storageType string |
| 37 | + exporterTypes []string |
| 38 | + pipeline map[string]*configmodels.Pipeline |
| 39 | + err string |
| 40 | + }{ |
| 41 | + { |
| 42 | + storageType: "elasticsearch", |
| 43 | + exporterTypes: []string{elasticsearch.TypeStr}, |
| 44 | + pipeline: map[string]*configmodels.Pipeline{ |
| 45 | + "traces": { |
| 46 | + InputType: configmodels.TracesDataType, |
| 47 | + Receivers: []string{"jaeger"}, |
| 48 | + Exporters: []string{elasticsearch.TypeStr}, |
| 49 | + Processors: []string{"batch"}, |
| 50 | + }, |
| 51 | + }, |
| 52 | + }, |
| 53 | + { |
| 54 | + storageType: "cassandra", |
| 55 | + exporterTypes: []string{cassandra.TypeStr}, |
| 56 | + pipeline: map[string]*configmodels.Pipeline{ |
| 57 | + "traces": { |
| 58 | + InputType: configmodels.TracesDataType, |
| 59 | + Receivers: []string{"jaeger"}, |
| 60 | + Exporters: []string{cassandra.TypeStr}, |
| 61 | + Processors: []string{"batch"}, |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + { |
| 66 | + storageType: "kafka", |
| 67 | + exporterTypes: []string{kafka.TypeStr}, |
| 68 | + pipeline: map[string]*configmodels.Pipeline{ |
| 69 | + "traces": { |
| 70 | + InputType: configmodels.TracesDataType, |
| 71 | + Receivers: []string{"jaeger"}, |
| 72 | + Exporters: []string{kafka.TypeStr}, |
| 73 | + Processors: []string{"batch"}, |
| 74 | + }, |
| 75 | + }, |
| 76 | + }, |
| 77 | + { |
| 78 | + storageType: "cassandra,elasticsearch", |
| 79 | + exporterTypes: []string{cassandra.TypeStr, elasticsearch.TypeStr}, |
| 80 | + pipeline: map[string]*configmodels.Pipeline{ |
| 81 | + "traces": { |
| 82 | + InputType: configmodels.TracesDataType, |
| 83 | + Receivers: []string{"jaeger"}, |
| 84 | + Exporters: []string{cassandra.TypeStr, elasticsearch.TypeStr}, |
| 85 | + Processors: []string{"batch"}, |
| 86 | + }, |
| 87 | + }, |
| 88 | + }, |
| 89 | + { |
| 90 | + storageType: "floppy", |
| 91 | + err: "unknown storage type: floppy", |
| 92 | + }, |
| 93 | + } |
| 94 | + for _, test := range tests { |
| 95 | + t.Run(test.storageType, func(t *testing.T) { |
| 96 | + cfg, err := Config(test.storageType, factories) |
| 97 | + if test.err != "" { |
| 98 | + require.Nil(t, cfg) |
| 99 | + assert.EqualError(t, err, test.err) |
| 100 | + return |
| 101 | + } |
| 102 | + require.NoError(t, err) |
| 103 | + require.NoError(t, config.ValidateConfig(cfg, zap.NewNop())) |
| 104 | + |
| 105 | + assert.Equal(t, 1, len(cfg.Receivers)) |
| 106 | + assert.Equal(t, "jaeger", cfg.Receivers["jaeger"].Name()) |
| 107 | + assert.Equal(t, 1, len(cfg.Processors)) |
| 108 | + assert.Equal(t, "batch", cfg.Processors["batch"].Name()) |
| 109 | + assert.Equal(t, len(test.exporterTypes), len(cfg.Exporters)) |
| 110 | + |
| 111 | + types := []string{} |
| 112 | + for _, v := range cfg.Exporters { |
| 113 | + types = append(types, v.Type()) |
| 114 | + } |
| 115 | + sort.Strings(types) |
| 116 | + assert.Equal(t, test.exporterTypes, types) |
| 117 | + assert.EqualValues(t, test.pipeline, cfg.Service.Pipelines) |
| 118 | + }) |
| 119 | + } |
| 120 | + |
| 121 | +} |
0 commit comments