mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
Merge pull request #46759 from zjj2wry/kubelet
Automatic merge from submit-queue (batch tested with PRs 46734, 46810, 46759, 46259, 46771) Improve code coverage for pkg/kubelet/images/image_gc_manager **What this PR does / why we need it**: #39559 #40780 code coverage from 74.5% to 77.4% **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
af64e0b8c9
@ -463,3 +463,63 @@ func TestGarbageCollectImageNotOldEnough(t *testing.T) {
|
||||
assert.EqualValues(1024, spaceFreed)
|
||||
assert.Len(fakeRuntime.ImageList, 1)
|
||||
}
|
||||
|
||||
func TestValidateImageGCPolicy(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
imageGCPolicy ImageGCPolicy
|
||||
expectErr string
|
||||
}{
|
||||
{
|
||||
name: "Test for LowThresholdPercent < HighThresholdPercent",
|
||||
imageGCPolicy: ImageGCPolicy{
|
||||
HighThresholdPercent: 2,
|
||||
LowThresholdPercent: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test for HighThresholdPercent < 0,",
|
||||
imageGCPolicy: ImageGCPolicy{
|
||||
HighThresholdPercent: -1,
|
||||
},
|
||||
expectErr: "invalid HighThresholdPercent -1, must be in range [0-100]",
|
||||
},
|
||||
{
|
||||
name: "Test for HighThresholdPercent > 100",
|
||||
imageGCPolicy: ImageGCPolicy{
|
||||
HighThresholdPercent: 101,
|
||||
},
|
||||
expectErr: "invalid HighThresholdPercent 101, must be in range [0-100]",
|
||||
},
|
||||
{
|
||||
name: "Test for LowThresholdPercent < 0",
|
||||
imageGCPolicy: ImageGCPolicy{
|
||||
LowThresholdPercent: -1,
|
||||
},
|
||||
expectErr: "invalid LowThresholdPercent -1, must be in range [0-100]",
|
||||
},
|
||||
{
|
||||
name: "Test for LowThresholdPercent > 100",
|
||||
imageGCPolicy: ImageGCPolicy{
|
||||
LowThresholdPercent: 101,
|
||||
},
|
||||
expectErr: "invalid LowThresholdPercent 101, must be in range [0-100]",
|
||||
},
|
||||
{
|
||||
name: "Test for LowThresholdPercent > HighThresholdPercent",
|
||||
imageGCPolicy: ImageGCPolicy{
|
||||
HighThresholdPercent: 1,
|
||||
LowThresholdPercent: 2,
|
||||
},
|
||||
expectErr: "LowThresholdPercent 2 can not be higher than HighThresholdPercent 1",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
if _, err := NewImageGCManager(nil, nil, nil, nil, tc.imageGCPolicy); err != nil {
|
||||
if err.Error() != tc.expectErr {
|
||||
t.Errorf("[%s:]Expected err:%v, but got:%v", tc.name, tc.expectErr, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user