findornext
This commit is contained in:
parent
405cf05341
commit
758f3ccd43
|
@ -38,9 +38,6 @@ func (ml *LocalID) Find(id string) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ml *LocalID) FindOrNext(id string) (int, error) {
|
func (ml *LocalID) FindOrNext(id string) (int, error) {
|
||||||
ml.mutex.Lock()
|
|
||||||
defer ml.mutex.Unlock()
|
|
||||||
|
|
||||||
lid, err := ml.Find(id)
|
lid, err := ml.Find(id)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, storage.ErrNotFound):
|
case errors.Is(err, storage.ErrNotFound):
|
||||||
|
|
|
@ -45,6 +45,14 @@ func TestLocalID(t *testing.T) {
|
||||||
if actLid != 1 {
|
if actLid != 1 {
|
||||||
t.Errorf("exp 1, git %v", actLid)
|
t.Errorf("exp 1, git %v", actLid)
|
||||||
}
|
}
|
||||||
|
t.Log("retrieve unknown")
|
||||||
|
actLid, actErr = repo.FindOrNext("new")
|
||||||
|
if actErr != nil {
|
||||||
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
|
}
|
||||||
|
if actLid != 2 {
|
||||||
|
t.Errorf("exp 2, got %v", actLid)
|
||||||
|
}
|
||||||
|
|
||||||
actIDs, actErr = repo.FindAll()
|
actIDs, actErr = repo.FindAll()
|
||||||
if actErr != nil {
|
if actErr != nil {
|
||||||
|
|
Loading…
Reference in New Issue