Skip to content
Snippets Groups Projects
Unverified Commit 68f830e6 authored by dlorenc's avatar dlorenc Committed by GitHub
Browse files

Add another helper to return the active shard from the flag set. (#549)


This should help out with #515.

Signed-off-by: default avatarDan Lorenc <lorenc.d@gmail.com>
parent 8208f16e
No related branches found
No related tags found
No related merge requests found
......@@ -104,3 +104,8 @@ func (l *LogRanges) ResolveVirtualIndex(index int) (uint64, uint64) {
// Return the last one!
return l.Ranges[len(l.Ranges)-1].TreeID, uint64(indexLeft)
}
// ActiveIndex returns the active shard index, always the last shard in the range
func (l *LogRanges) ActiveIndex() uint64 {
return l.Ranges[len(l.Ranges)-1].TreeID
}
......@@ -23,9 +23,10 @@ import (
func TestLogRanges_Set(t *testing.T) {
tests := []struct {
name string
arg string
want []LogRange
name string
arg string
want []LogRange
active uint64
}{
{
name: "one, no length",
......@@ -36,6 +37,7 @@ func TestLogRanges_Set(t *testing.T) {
TreeLength: 0,
},
},
active: 1234,
},
{
name: "two",
......@@ -50,6 +52,7 @@ func TestLogRanges_Set(t *testing.T) {
TreeLength: 0,
},
},
active: 7234,
},
}
for _, tt := range tests {
......@@ -62,6 +65,11 @@ func TestLogRanges_Set(t *testing.T) {
if diff := cmp.Diff(tt.want, l.Ranges); diff != "" {
t.Errorf(diff)
}
active := l.ActiveIndex()
if active != tt.active {
t.Errorf("LogRanges.Active() expected %d no error, got %d", tt.active, active)
}
})
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment