aboutsummaryrefslogtreecommitdiff
path: root/microprom/labels_test.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-08-18 13:40:30 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-08-18 13:40:30 +0200
commit5cc0f9db288ffaf44d104974707338d52530cece (patch)
treef0ad530dd072c55c6f46dfea23af993fb31333d4 /microprom/labels_test.go
parentab5012e0083ff6623ffab78f52f9ea1120d80ffb (diff)
parenta3ccdd9f491c20771cfda343ebebd4b5d0ea6602 (diff)
downloadgo-gg-5cc0f9db288ffaf44d104974707338d52530cece.tar.gz
Merge branch 'microprom'
Diffstat (limited to 'microprom/labels_test.go')
-rw-r--r--microprom/labels_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/microprom/labels_test.go b/microprom/labels_test.go
new file mode 100644
index 0000000..0414be8
--- /dev/null
+++ b/microprom/labels_test.go
@@ -0,0 +1,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\""`)
+}