fix histogram vec compare using ignore fields

This commit is contained in:
Paco Xu 2023-07-14 16:06:47 +08:00
parent 9b6af80a63
commit 171b19d9fe

View File

@ -23,6 +23,7 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
dto "github.com/prometheus/client_model/go"
"k8s.io/component-base/metrics"
"k8s.io/utils/pointer"
@ -584,7 +585,7 @@ func TestGetHistogramVecFromGatherer(t *testing.T) {
vec.WithLabelValues("value1-1", "value2-1").Observe(4.5)
metricName := fmt.Sprintf("%s_%s_%s", HistogramOpts.Namespace, HistogramOpts.Subsystem, HistogramOpts.Name)
histogramVec, _ := GetHistogramVecFromGatherer(gather, metricName, tt.lvMap)
if diff := cmp.Diff(tt.wantVec, histogramVec); diff != "" {
if diff := cmp.Diff(tt.wantVec, histogramVec, cmpopts.IgnoreFields(dto.Histogram{}, "state", "sizeCache", "unknownFields"), cmpopts.IgnoreFields(dto.Bucket{}, "state", "sizeCache", "unknownFields")); diff != "" {
t.Errorf("Got unexpected HistogramVec (-want +got):\n%s", diff)
}
})