Possible partial delete
go
Wrap Lines
Raw package scrapers
import (
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
)
const (
ipAddress = "192.168.10.1"
minerSN = "1234567890"
macAddress = "00:00:00:00:00:00"
epsilon = 1e-5
)
func TestRegistryResetWorks(t *testing.T) {
registry := prometheus.NewRegistry()
mc := NewWhatsminerMetricCollection(registry)
labels := prometheus.Labels{
LabelIPAddress: ipAddress,
LabelMinerSN: minerSN,
LabelMACAddress: macAddress,
}
const hashRate = 100
mc.RTHashRateGauge.With(labels).Set(hashRate)
metrics, err := registry.Gather()
assert.NoError(t, err)
assert.Equal(t, 1, len(metrics))
assert.Equal(t, "whatsminer_hash_realtime", metrics[0].GetName())
assert.InEpsilon(t, hashRate, metrics[0].GetMetric()[0].GetGauge().GetValue(), epsilon)
mc.RTHashRateGauge.DeletePartialMatch(prometheus.Labels{
LabelIPAddress: ipAddress,
})
metrics, err = registry.Gather()
assert.NoError(t, err)
assert.Equal(t, 0, len(metrics))
}