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

Function TestVectorJSON

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

SampleValueTypeAlias · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected