| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package otelconftelemetry |
| 5 |
|
| 6 |
import ( |
| 7 |
"strconv" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
"github.com/stretchr/testify/require" |
| 12 |
|
| 13 |
"go.opentelemetry.io/collector/featuregate" |
| 14 |
) |
| 15 |
|
| 16 |
func TestDefaultConfig(t *testing.T) { |
| 17 |
tests := []struct { |
| 18 |
expected string |
| 19 |
gate bool |
| 20 |
}{ |
| 21 |
{ |
| 22 |
expected: "localhost", |
| 23 |
gate: true, |
| 24 |
}, |
| 25 |
{ |
| 26 |
expected: "", |
| 27 |
gate: false, |
| 28 |
}, |
| 29 |
} |
| 30 |
|
| 31 |
for _, tt := range tests { |
| 32 |
t.Run("UseLocalHostAsDefaultMetricsAddress/"+strconv.FormatBool(tt.gate), func(t *testing.T) { |
| 33 |
prev := useLocalHostAsDefaultMetricsAddressFeatureGate.IsEnabled() |
| 34 |
require.NoError(t, featuregate.GlobalRegistry().Set(useLocalHostAsDefaultMetricsAddressFeatureGate.ID(), tt.gate)) |
| 35 |
defer func() { |
| 36 |
|
| 37 |
require.NoError(t, featuregate.GlobalRegistry().Set(useLocalHostAsDefaultMetricsAddressFeatureGate.ID(), prev)) |
| 38 |
}() |
| 39 |
cfg := NewFactory().CreateDefaultConfig() |
| 40 |
require.Len(t, cfg.(*Config).Metrics.Readers, 1) |
| 41 |
assert.Equal(t, tt.expected, *cfg.(*Config).Metrics.Readers[0].Pull.Exporter.Prometheus.Host) |
| 42 |
assert.Equal(t, 8888, *cfg.(*Config).Metrics.Readers[0].Pull.Exporter.Prometheus.Port) |
| 43 |
}) |
| 44 |
} |
| 45 |
} |