fix data race in test

Signed-off-by: lixd <xueduan.li@gmail.com>
This commit is contained in:
lixd 2023-08-25 09:57:28 +08:00
parent 9533cfe2ee
commit 12c0c08e65

View File

@ -81,6 +81,12 @@ type FakeVersion struct {
Version string Version string
} }
func snapshot(imageList []kubecontainer.Image) []kubecontainer.Image {
result := make([]kubecontainer.Image, len(imageList))
copy(result, imageList)
return result
}
func (fv *FakeVersion) String() string { func (fv *FakeVersion) String() string {
return fv.Version return fv.Version
} }
@ -362,7 +368,7 @@ func (f *FakeRuntime) ListImages(_ context.Context) ([]kubecontainer.Image, erro
defer f.Unlock() defer f.Unlock()
f.CalledFunctions = append(f.CalledFunctions, "ListImages") f.CalledFunctions = append(f.CalledFunctions, "ListImages")
return f.ImageList, f.Err return snapshot(f.ImageList), f.Err
} }
func (f *FakeRuntime) RemoveImage(_ context.Context, image kubecontainer.ImageSpec) error { func (f *FakeRuntime) RemoveImage(_ context.Context, image kubecontainer.ImageSpec) error {