github.com/theQRL/go-zond@v0.1.1/metrics/gauge_info_test.go (about) 1 package metrics 2 3 import ( 4 "testing" 5 ) 6 7 func TestGaugeInfoJsonString(t *testing.T) { 8 g := NewGaugeInfo() 9 g.Update(GaugeInfoValue{ 10 "chain_id": "5", 11 "anotherKey": "any_string_value", 12 "third_key": "anything", 13 }, 14 ) 15 want := `{"anotherKey":"any_string_value","chain_id":"5","third_key":"anything"}` 16 17 original := g.Snapshot() 18 g.Update(GaugeInfoValue{"value": "updated"}) 19 20 if have := original.Value().String(); have != want { 21 t.Errorf("\nhave: %v\nwant: %v\n", have, want) 22 } 23 if have, want := g.Snapshot().Value().String(), `{"value":"updated"}`; have != want { 24 t.Errorf("\nhave: %v\nwant: %v\n", have, want) 25 } 26 } 27 28 func TestGetOrRegisterGaugeInfo(t *testing.T) { 29 r := NewRegistry() 30 NewRegisteredGaugeInfo("foo", r).Update( 31 GaugeInfoValue{"chain_id": "5"}) 32 g := GetOrRegisterGaugeInfo("foo", r).Snapshot() 33 if have, want := g.Value().String(), `{"chain_id":"5"}`; have != want { 34 t.Errorf("have\n%v\nwant\n%v\n", have, want) 35 } 36 }