| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package prometheus // import "go.opentelemetry.io/contrib/bridges/prometheus" |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/prometheus/client_golang/prometheus" |
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
) |
| 12 |
|
| 13 |
func TestNewConfig(t *testing.T) { |
| 14 |
otherRegistry := prometheus.NewRegistry() |
| 15 |
|
| 16 |
testCases := []struct { |
| 17 |
name string |
| 18 |
options []Option |
| 19 |
wantConfig config |
| 20 |
}{ |
| 21 |
{ |
| 22 |
name: "Default", |
| 23 |
options: nil, |
| 24 |
wantConfig: config{ |
| 25 |
gatherers: []prometheus.Gatherer{prometheus.DefaultGatherer}, |
| 26 |
}, |
| 27 |
}, |
| 28 |
{ |
| 29 |
name: "With a different gatherer", |
| 30 |
options: []Option{WithGatherer(otherRegistry)}, |
| 31 |
wantConfig: config{ |
| 32 |
gatherers: []prometheus.Gatherer{otherRegistry}, |
| 33 |
}, |
| 34 |
}, |
| 35 |
{ |
| 36 |
name: "Multiple gatherers", |
| 37 |
options: []Option{WithGatherer(otherRegistry), WithGatherer(prometheus.DefaultGatherer)}, |
| 38 |
wantConfig: config{ |
| 39 |
gatherers: []prometheus.Gatherer{otherRegistry, prometheus.DefaultGatherer}, |
| 40 |
}, |
| 41 |
}, |
| 42 |
} |
| 43 |
for _, tt := range testCases { |
| 44 |
t.Run(tt.name, func(t *testing.T) { |
| 45 |
cfg := newConfig(tt.options...) |
| 46 |
assert.Equal(t, tt.wantConfig, cfg) |
| 47 |
}) |
| 48 |
} |
| 49 |
} |