diff --git a/tools/cache/delta_fifo.go b/tools/cache/delta_fifo.go index f648673e..ea25122a 100644 --- a/tools/cache/delta_fifo.go +++ b/tools/cache/delta_fifo.go @@ -340,7 +340,7 @@ func (f *DeltaFIFO) AddIfNotPresent(obj interface{}) error { if !ok { return fmt.Errorf("object must be of type deltas, but got: %#v", obj) } - id, err := f.KeyOf(deltas.Newest().Object) + id, err := f.KeyOf(deltas) if err != nil { return KeyError{obj, err} } diff --git a/tools/cache/delta_fifo_test.go b/tools/cache/delta_fifo_test.go index ec4e4ff2..92247c4b 100644 --- a/tools/cache/delta_fifo_test.go +++ b/tools/cache/delta_fifo_test.go @@ -17,6 +17,7 @@ limitations under the License. package cache import ( + "errors" "fmt" "reflect" "runtime" @@ -541,6 +542,11 @@ func TestDeltaFIFO_detectLineJumpers(t *testing.T) { func TestDeltaFIFO_addIfNotPresent(t *testing.T) { f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) + emptyDeltas := Deltas{} + if err := f.AddIfNotPresent(emptyDeltas); err == nil || !errors.Is(err, ErrZeroLengthDeltasObject) { + t.Errorf("Expected error '%v', got %v", ErrZeroLengthDeltasObject, err) + } + f.Add(mkFifoObj("b", 3)) b3 := Pop(f) f.Add(mkFifoObj("c", 4))