From a25f874ec4d79f7ff3be78c49e6e6d4876b8c748 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Fri, 28 Apr 2017 15:53:48 +0200 Subject: [PATCH] Simplify Labels.Equals() Also extend the Compare() tests to also test Labels.Equals(). --- labels/labels.go | 2 +- labels/labels_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/labels/labels.go b/labels/labels.go index c1b54f0aa1..2ee42360e0 100644 --- a/labels/labels.go +++ b/labels/labels.go @@ -84,7 +84,7 @@ func (ls Labels) Equals(o Labels) bool { return false } for i, l := range ls { - if l.Name != o[i].Name || l.Value != o[i].Value { + if o[i] != l { return false } } diff --git a/labels/labels_test.go b/labels/labels_test.go index 459a724205..9a613b6818 100644 --- a/labels/labels_test.go +++ b/labels/labels_test.go @@ -28,7 +28,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestCompare(t *testing.T) { +func TestCompareAndEquals(t *testing.T) { cases := []struct { a, b []Label res int @@ -88,6 +88,7 @@ func TestCompare(t *testing.T) { a, b := New(c.a...), New(c.b...) require.Equal(t, c.res, Compare(a, b)) + require.Equal(t, c.res == 0, a.Equals(b)) } }