From 68f830e6255dd3f01bdfd1e0ea1a0815df12a276 Mon Sep 17 00:00:00 2001 From: dlorenc <dlorenc@google.com> Date: Tue, 21 Dec 2021 02:54:06 -0600 Subject: [PATCH] Add another helper to return the active shard from the flag set. (#549) This should help out with #515. Signed-off-by: Dan Lorenc <lorenc.d@gmail.com> --- cmd/rekor-server/app/flags.go | 5 +++++ cmd/rekor-server/app/flags_test.go | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cmd/rekor-server/app/flags.go b/cmd/rekor-server/app/flags.go index c2040d8..76705f2 100644 --- a/cmd/rekor-server/app/flags.go +++ b/cmd/rekor-server/app/flags.go @@ -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 +} diff --git a/cmd/rekor-server/app/flags_test.go b/cmd/rekor-server/app/flags_test.go index 5c9990f..ab82b26 100644 --- a/cmd/rekor-server/app/flags_test.go +++ b/cmd/rekor-server/app/flags_test.go @@ -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) + } }) } } -- GitLab