From bfbe25e926cbe45ed70b8e0df6ccec78c04d7247 Mon Sep 17 00:00:00 2001 From: dongjiang1989 Date: Thu, 18 Apr 2024 20:19:10 +0800 Subject: [PATCH] dongjiang, change go-cmp to reflect Signed-off-by: dongjiang1989 --- prometheus/testutil/testutil.go | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/prometheus/testutil/testutil.go b/prometheus/testutil/testutil.go index 98ed75b..4babdfc 100644 --- a/prometheus/testutil/testutil.go +++ b/prometheus/testutil/testutil.go @@ -44,7 +44,6 @@ import ( "net/http" "reflect" - "github.com/google/go-cmp/cmp" dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/expfmt" "google.golang.org/protobuf/proto" @@ -277,37 +276,12 @@ func compare(got, want []*dto.MetricFamily) error { return fmt.Errorf("encoding expected metrics failed: %w", err) } } - if diffErr := diff(gotBuf.String(), wantBuf.String()); diffErr != "" { - return fmt.Errorf(diffErr) + if diffErr := reflect.DeepEqual(gotBuf, wantBuf); !diffErr { + return fmt.Errorf("metrics diff") } return nil } -// diff returns a diff of both values as long as both are of the same type and -// are a struct, map, slice, array or string. Otherwise it returns an empty string. -func diff(expected, actual interface{}) string { - if expected == nil || actual == nil { - return "" - } - - et, ek := typeAndKind(expected) - at, _ := typeAndKind(actual) - if et != at { - return "" - } - - if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array && ek != reflect.String { - return "" - } - - diff := cmp.Diff(expected, actual) - if diff == "" { - return "" - } - - return "\n\nDiff:\n" + diff -} - // typeAndKind returns the type and kind of the given interface{} func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) { t := reflect.TypeOf(v)