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 15package otlphttpexporter 16 17import ( 18 "path" 19 "testing" 20 "time" 21 22 "github.com/stretchr/testify/assert" 23 "github.com/stretchr/testify/require" 24 25 "go.opentelemetry.io/collector/component/componenttest" 26 "go.opentelemetry.io/collector/config" 27 "go.opentelemetry.io/collector/config/confighttp" 28 "go.opentelemetry.io/collector/config/configtest" 29 "go.opentelemetry.io/collector/config/configtls" 30 "go.opentelemetry.io/collector/exporter/exporterhelper" 31) 32 33func TestLoadConfig(t *testing.T) { 34 factories, err := componenttest.NopFactories() 35 assert.NoError(t, err) 36 37 factory := NewFactory() 38 factories.Exporters[typeStr] = factory 39 cfg, err := configtest.LoadConfigAndValidate(path.Join(".", "testdata", "config.yaml"), factories) 40 41 require.NoError(t, err) 42 require.NotNil(t, cfg) 43 44 e0 := cfg.Exporters[config.NewID(typeStr)] 45 assert.Equal(t, e0, factory.CreateDefaultConfig()) 46 47 e1 := cfg.Exporters[config.NewIDWithName(typeStr, "2")] 48 assert.Equal(t, e1, 49 &Config{ 50 ExporterSettings: config.NewExporterSettings(config.NewIDWithName(typeStr, "2")), 51 RetrySettings: exporterhelper.RetrySettings{ 52 Enabled: true, 53 InitialInterval: 10 * time.Second, 54 MaxInterval: 1 * time.Minute, 55 MaxElapsedTime: 10 * time.Minute, 56 }, 57 QueueSettings: exporterhelper.QueueSettings{ 58 Enabled: true, 59 NumConsumers: 2, 60 QueueSize: 10, 61 }, 62 HTTPClientSettings: confighttp.HTTPClientSettings{ 63 Headers: map[string]string{ 64 "can you have a . here?": "F0000000-0000-0000-0000-000000000000", 65 "header1": "234", 66 "another": "somevalue", 67 }, 68 Endpoint: "https://1.2.3.4:1234", 69 TLSSetting: configtls.TLSClientSetting{ 70 TLSSetting: configtls.TLSSetting{ 71 CAFile: "/var/lib/mycert.pem", 72 CertFile: "certfile", 73 KeyFile: "keyfile", 74 }, 75 Insecure: true, 76 }, 77 ReadBufferSize: 123, 78 WriteBufferSize: 345, 79 Timeout: time.Second * 10, 80 }, 81 Compression: "gzip", 82 }) 83} 84