mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
client-go/cache: fix the AddIfNotPresent method of the DeltaFIFO
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
parent
38ff5f6884
commit
c75bd4a535
@ -340,7 +340,7 @@ func (f *DeltaFIFO) AddIfNotPresent(obj interface{}) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("object must be of type deltas, but got: %#v", obj)
|
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 {
|
if err != nil {
|
||||||
return KeyError{obj, err}
|
return KeyError{obj, err}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -541,6 +542,11 @@ func TestDeltaFIFO_detectLineJumpers(t *testing.T) {
|
|||||||
func TestDeltaFIFO_addIfNotPresent(t *testing.T) {
|
func TestDeltaFIFO_addIfNotPresent(t *testing.T) {
|
||||||
f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc})
|
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))
|
f.Add(mkFifoObj("b", 3))
|
||||||
b3 := Pop(f)
|
b3 := Pop(f)
|
||||||
f.Add(mkFifoObj("c", 4))
|
f.Add(mkFifoObj("c", 4))
|
||||||
|
Loading…
Reference in New Issue
Block a user