MCPcopy Create free account
hub / github.com/prometheus/common / TestEncode

Function TestEncode

expfmt/encode_test.go:203–303  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

201}
202
203func TestEncode(t *testing.T) {
204 metric1 := &dto.MetricFamily{
205 Name: proto.String("foo_metric"),
206 Type: dto.MetricType_UNTYPED.Enum(),
207 Unit: proto.String("seconds"),
208 Metric: []*dto.Metric{
209 {
210 Untyped: &dto.Untyped{
211 Value: proto.Float64(1.234),
212 },
213 },
214 },
215 }
216
217 scenarios := []struct {
218 metric *dto.MetricFamily
219 format Format
220 options []EncoderOption
221 expOut string
222 }{
223 // 1: Untyped ProtoDelim
224 {
225 metric: metric1,
226 format: FmtProtoDelim,
227 },
228 // 2: Untyped FmtProtoCompact
229 {
230 metric: metric1,
231 format: FmtProtoCompact,
232 },
233 // 3: Untyped FmtProtoText
234 {
235 metric: metric1,
236 format: FmtProtoText,
237 },
238 // 4: Untyped FmtText
239 {
240 metric: metric1,
241 format: FmtText,
242 expOut: `# TYPE foo_metric untyped
243foo_metric 1.234
244`,
245 },
246 // 5: Untyped FmtOpenMetrics_0_0_1
247 {
248 metric: metric1,
249 format: FmtOpenMetrics_0_0_1,
250 expOut: `# TYPE foo_metric unknown
251# UNIT foo_metric seconds
252foo_metric 1.234
253`,
254 },
255 // 6: Untyped FmtOpenMetrics_1_0_0
256 {
257 metric: metric1,
258 format: FmtOpenMetrics_1_0_0,
259 expOut: `# TYPE foo_metric unknown
260# UNIT foo_metric seconds

Callers

nothing calls this directly

Calls 3

EncodeMethod · 0.95
NewEncoderFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…