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

Function TestVectorJSON

model/value_float_test.go:197–260  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

195}
196
197func TestVectorJSON(t *testing.T) {
198 input := []struct {
199 plain string
200 value Vector
201 }{
202 {
203 plain: `[]`,
204 value: Vector{},
205 },
206 {
207 plain: `[{"metric":{"__name__":"test_metric"},"value":[1234.567,"123.1"]}]`,
208 value: Vector{&Sample{
209 Metric: Metric{
210 MetricNameLabel: "test_metric",
211 },
212 Value: 123.1,
213 Timestamp: 1234567,
214 }},
215 },
216 {
217 plain: `[{"metric":{"__name__":"test_metric"},"value":[1234.567,"123.1"]},{"metric":{"foo":"bar"},"value":[1.234,"+Inf"]}]`,
218 value: Vector{
219 &Sample{
220 Metric: Metric{
221 MetricNameLabel: "test_metric",
222 },
223 Value: 123.1,
224 Timestamp: 1234567,
225 },
226 &Sample{
227 Metric: Metric{
228 "foo": "bar",
229 },
230 Value: SampleValue(math.Inf(1)),
231 Timestamp: 1234,
232 },
233 },
234 },
235 }
236
237 for _, test := range input {
238 b, err := json.Marshal(test.value)
239 if err != nil {
240 t.Error(err)
241 continue
242 }
243
244 if string(b) != test.plain {
245 t.Errorf("encoding error: expected %q, got %q", test.plain, b)
246 continue
247 }
248
249 var vec Vector
250 err = json.Unmarshal(b, &vec)
251 if err != nil {
252 t.Error(err)
253 continue
254 }

Callers

nothing calls this directly

Calls 2

SampleValueTypeAlias · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…