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

Function TestStringJSON

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

Source from the content-addressed store, hash-verified

209}
210
211func TestStringJSON(t *testing.T) {
212 input := []struct {
213 plain string
214 value String
215 }{
216 {
217 plain: `[123.456,"test"]`,
218 value: String{
219 Timestamp: 123456,
220 Value: "test",
221 },
222 },
223 {
224 plain: `[123123.456,"台北"]`,
225 value: String{
226 Timestamp: 123123456,
227 Value: "台北",
228 },
229 },
230 }
231
232 for _, test := range input {
233 b, err := json.Marshal(test.value)
234 if err != nil {
235 t.Error(err)
236 continue
237 }
238
239 if string(b) != test.plain {
240 t.Errorf("encoding error: expected %q, got %q", test.plain, b)
241 continue
242 }
243
244 var sv String
245 err = json.Unmarshal(b, &sv)
246 if err != nil {
247 t.Error(err)
248 continue
249 }
250
251 if sv != test.value {
252 t.Errorf("decoding error: expected %v, got %v", test.value, sv)
253 }
254 }
255}
256
257func TestVectorSort(t *testing.T) {
258 input := Vector{

Callers

nothing calls this directly

Calls 1

ErrorMethod · 0.80

Tested by

no test coverage detected