(t *testing.T)
| 144 | } |
| 145 | |
| 146 | func 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 | |
| 194 | func TestCounterAddLarge(t *testing.T) { |
| 195 | now := time.Now() |
nothing calls this directly
no test coverage detected