MCPcopy
hub / github.com/prometheus/client_golang / TestCounterAddInf

Function TestCounterAddInf

prometheus/counter_test.go:146–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

144}
145
146func TestCounterAddInf(t *testing.T) {
147 now := time.Now()
148
149 counter := NewCounter(CounterOpts{
150 Name: "test",
151 Help: "test help",
152 now: func() time.Time { return now },
153 }).(*counter)
154
155 counter.Inc()
156 if expected, got := 0.0, math.Float64frombits(counter.valBits); expected != got {
157 t.Errorf("Expected %f, got %f.", expected, got)
158 }
159 if expected, got := uint64(1), counter.valInt; expected != got {
160 t.Errorf("Expected %d, got %d.", expected, got)
161 }
162
163 counter.Add(math.Inf(1))
164 if expected, got := math.Inf(1), math.Float64frombits(counter.valBits); expected != got {
165 t.Errorf("valBits expected %f, got %f.", expected, got)
166 }
167 if expected, got := uint64(1), counter.valInt; expected != got {
168 t.Errorf("valInts expected %d, got %d.", expected, got)
169 }
170
171 counter.Inc()
172 if expected, got := math.Inf(1), math.Float64frombits(counter.valBits); expected != got {
173 t.Errorf("Expected %f, got %f.", expected, got)
174 }
175 if expected, got := uint64(2), counter.valInt; expected != got {
176 t.Errorf("Expected %d, got %d.", expected, got)
177 }
178
179 m := &dto.Metric{}
180 counter.Write(m)
181
182 expected := &dto.Metric{
183 Counter: &dto.Counter{
184 Value: proto.Float64(math.Inf(1)),
185 CreatedTimestamp: timestamppb.New(now),
186 },
187 }
188
189 if !proto.Equal(expected, m) {
190 t.Errorf("expected %q, got %q", expected, m)
191 }
192}
193
194func TestCounterAddLarge(t *testing.T) {
195 now := time.Now()

Callers

nothing calls this directly

Calls 4

NewCounterFunction · 0.70
IncMethod · 0.65
AddMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected