From f6e2cc3890ea9a11e4aad38d67a91751ecc38304 Mon Sep 17 00:00:00 2001 From: Sergey Cherepanov Date: Wed, 1 Feb 2023 21:38:47 +0300 Subject: [PATCH] ldiff: Len --- app/ldiff/diff.go | 8 ++++++++ app/ldiff/diff_test.go | 1 + 2 files changed, 9 insertions(+) diff --git a/app/ldiff/diff.go b/app/ldiff/diff.go index dd49d980..f0a2f197 100644 --- a/app/ldiff/diff.go +++ b/app/ldiff/diff.go @@ -94,6 +94,8 @@ type Diff interface { Ids() []string // Hash returns hash of all elements in the diff Hash() string + // Len returns count of elements in the diff + Len() int } // Remote interface for using in the Diff @@ -159,6 +161,12 @@ func (d *diff) Ids() (ids []string) { return } +func (d *diff) Len() int { + d.mu.RLock() + defer d.mu.RUnlock() + return d.sl.Len() +} + func (d *diff) Elements() (elements []Element) { d.mu.RLock() defer d.mu.RUnlock() diff --git a/app/ldiff/diff_test.go b/app/ldiff/diff_test.go index 682bf1d5..e15f6b82 100644 --- a/app/ldiff/diff_test.go +++ b/app/ldiff/diff_test.go @@ -179,6 +179,7 @@ func TestDiff_Ids(t *testing.T) { gotIds := d.Ids() sort.Strings(gotIds) assert.Equal(t, ids, gotIds) + assert.Equal(t, len(ids), d.Len()) } func TestDiff_Elements(t *testing.T) {