From f4c05be86273b8c4eac0759d11a5a54b96f4aa21 Mon Sep 17 00:00:00 2001 From: Eric Solender Date: Thu, 28 Oct 2021 15:17:03 -0400 Subject: [PATCH] Added function to get number of system updates --- neo4j/resultsummary.go | 6 ++++++ neo4j/resultsummary_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/neo4j/resultsummary.go b/neo4j/resultsummary.go index 0d82b332..faea9f93 100644 --- a/neo4j/resultsummary.go +++ b/neo4j/resultsummary.go @@ -93,6 +93,8 @@ type Counters interface { ConstraintsAdded() int // The number of constraints removed from the schema. ConstraintsRemoved() int + // The number of system updates + SystemUpdates() int } type Statement interface { @@ -246,6 +248,10 @@ func (s *resultSummary) getCounter(n string) int { return s.sum.Counters[n] } +func (s *resultSummary) SystemUpdates() int { + return s.getCounter(db.SystemUpdates) +} + func (s *resultSummary) NodesCreated() int { return s.getCounter(db.NodesCreated) } diff --git a/neo4j/resultsummary_test.go b/neo4j/resultsummary_test.go index 0e902feb..fbf51de8 100644 --- a/neo4j/resultsummary_test.go +++ b/neo4j/resultsummary_test.go @@ -43,3 +43,29 @@ func TestProfiledPlan(st *testing.T) { } }) } + +func TestCounters(st *testing.T) { + + emptySummary := resultSummary{sum: &db.Summary{}} + summary := resultSummary{ + sum: &db.Summary{ + Counters: map[string]int{ + "system-updates": 42, + }, + }, + } + + st.Run("Returns empty system update count by default", func(t *testing.T) { + actual := emptySummary.Counters().SystemUpdates() + if actual != 0 { + t.Errorf("Expected 0 system update, got %d", actual) + } + }) + + st.Run("Returns populated system update count", func(t *testing.T) { + actual := summary.Counters().SystemUpdates() + if actual != 42 { + t.Errorf("Expected 42 system updates, got %d", actual) + } + }) +} \ No newline at end of file