Skip to content

Commit

Permalink
Added function to get number of system updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Solender authored and fbiville committed Dec 2, 2021
1 parent 5f22fe0 commit f4c05be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions neo4j/resultsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
26 changes: 26 additions & 0 deletions neo4j/resultsummary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}

0 comments on commit f4c05be

Please sign in to comment.