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

Function TestScalarJSON

model/value_test.go:158–209  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestScalarJSON(t *testing.T) {
159 input := []struct {
160 plain string
161 value Scalar
162 }{
163 {
164 plain: `[123.456,"456"]`,
165 value: Scalar{
166 Timestamp: 123456,
167 Value: 456,
168 },
169 },
170 {
171 plain: `[123123.456,"+Inf"]`,
172 value: Scalar{
173 Timestamp: 123123456,
174 Value: SampleValue(math.Inf(1)),
175 },
176 },
177 {
178 plain: `[123123.456,"-Inf"]`,
179 value: Scalar{
180 Timestamp: 123123456,
181 Value: SampleValue(math.Inf(-1)),
182 },
183 },
184 }
185
186 for _, test := range input {
187 b, err := json.Marshal(test.value)
188 if err != nil {
189 t.Error(err)
190 continue
191 }
192
193 if string(b) != test.plain {
194 t.Errorf("encoding error: expected %q, got %q", test.plain, b)
195 continue
196 }
197
198 var sv Scalar
199 err = json.Unmarshal(b, &sv)
200 if err != nil {
201 t.Error(err)
202 continue
203 }
204
205 if sv != test.value {
206 t.Errorf("decoding error: expected %v, got %v", test.value, sv)
207 }
208 }
209}
210
211func TestStringJSON(t *testing.T) {
212 input := []struct {

Callers

nothing calls this directly

Calls 2

SampleValueTypeAlias · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected