findornext

This commit is contained in:
Erik Winter 2024-10-16 07:20:08 +02:00
parent 405cf05341
commit 758f3ccd43
2 changed files with 8 additions and 3 deletions

View File

@ -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):

View File

@ -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 {