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

Function TestSampleJSON

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

Source from the content-addressed store, hash-verified

151}
152
153func TestSampleJSON(t *testing.T) {
154 input := []struct {
155 plain string
156 value Sample
157 }{
158 {
159 plain: `{"metric":{"__name__":"test_metric"},"value":[1234.567,"123.1"]}`,
160 value: Sample{
161 Metric: Metric{
162 MetricNameLabel: "test_metric",
163 },
164 Value: 123.1,
165 Timestamp: 1234567,
166 },
167 },
168 }
169
170 for _, test := range input {
171 b, err := json.Marshal(test.value)
172 if err != nil {
173 t.Error(err)
174 continue
175 }
176
177 if string(b) != test.plain {
178 t.Errorf("encoding error: expected %q, got %q", test.plain, b)
179 continue
180 }
181
182 var sv Sample
183 err = json.Unmarshal(b, &sv)
184 if err != nil {
185 t.Error(err)
186 continue
187 }
188
189 if !reflect.DeepEqual(sv, test.value) {
190 t.Errorf("decoding error: expected %v, got %v", test.value, sv)
191 }
192 }
193}
194
195func TestVectorJSON(t *testing.T) {
196 input := []struct {

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.80

Tested by

no test coverage detected