blob: 0414be89293a97c7293b84a3499a618c748da3cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
// SPDX-License-Identifier: Apache-2.0
package microprom_test
import (
"testing"
"go.xyrillian.de/gg/assert"
"go.xyrillian.de/gg/microprom"
)
func TestFormatLabels(t *testing.T) {
ms := microprom.NewMetricSet(microprom.SyntaxOpenMetricsV1, nil)
// the basic example from the documentation
names := microprom.NewLabelNames("foo", "hello")
labels := ms.FormatLabels(names, "bar", "world")
assert.Equal(t, labels, `foo="bar",hello="world"`)
// test escaping label values
labels = ms.FormatLabels(names, "bar\\\n\\bar", `"universe\world"`)
assert.Equal(t, labels, `foo="bar\\\n\\bar",hello="\"universe\\world\""`)
}
|