File: config_test.go

package info (click to toggle)
golang-opentelemetry-contrib 0.56.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,884 kB
  • sloc: makefile: 278; sh: 211; sed: 1
file content (49 lines) | stat: -rw-r--r-- 1,170 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package prometheus // import "go.opentelemetry.io/contrib/bridges/prometheus"

import (
	"testing"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/stretchr/testify/assert"
)

func TestNewConfig(t *testing.T) {
	otherRegistry := prometheus.NewRegistry()

	testCases := []struct {
		name       string
		options    []Option
		wantConfig config
	}{
		{
			name:    "Default",
			options: nil,
			wantConfig: config{
				gatherers: []prometheus.Gatherer{prometheus.DefaultGatherer},
			},
		},
		{
			name:    "With a different gatherer",
			options: []Option{WithGatherer(otherRegistry)},
			wantConfig: config{
				gatherers: []prometheus.Gatherer{otherRegistry},
			},
		},
		{
			name:    "Multiple gatherers",
			options: []Option{WithGatherer(otherRegistry), WithGatherer(prometheus.DefaultGatherer)},
			wantConfig: config{
				gatherers: []prometheus.Gatherer{otherRegistry, prometheus.DefaultGatherer},
			},
		},
	}
	for _, tt := range testCases {
		t.Run(tt.name, func(t *testing.T) {
			cfg := newConfig(tt.options...)
			assert.Equal(t, tt.wantConfig, cfg)
		})
	}
}