mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Fix unit tests calling SetFeatureGateDuringTest incorrectly
This commit is contained in:
parent
4dca07ef7e
commit
70ad4dff48
@ -6383,8 +6383,7 @@ func TestValidatePodSpec(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// original value will be restored by previous defer
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodShareProcessNamespace, false)()
|
||||||
utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodShareProcessNamespace, false)
|
|
||||||
|
|
||||||
featuregatedCases := map[string]core.PodSpec{
|
featuregatedCases := map[string]core.PodSpec{
|
||||||
"set ShareProcessNamespace": {
|
"set ShareProcessNamespace": {
|
||||||
|
@ -1161,7 +1161,8 @@ func TestVolumeModeCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for name, scenario := range scenarios {
|
for name, scenario := range scenarios {
|
||||||
recover := utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, scenario.enableBlock)
|
t.Run(name, func(t *testing.T) {
|
||||||
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, scenario.enableBlock)()
|
||||||
expectedMismatch, err := checkVolumeModeMismatches(&scenario.pvc.Spec, &scenario.vol.Spec)
|
expectedMismatch, err := checkVolumeModeMismatches(&scenario.pvc.Spec, &scenario.vol.Spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Unexpected failure for checkVolumeModeMismatches: %v", err)
|
t.Errorf("Unexpected failure for checkVolumeModeMismatches: %v", err)
|
||||||
@ -1173,7 +1174,7 @@ func TestVolumeModeCheck(t *testing.T) {
|
|||||||
if !expectedMismatch && scenario.isExpectedMismatch {
|
if !expectedMismatch && scenario.isExpectedMismatch {
|
||||||
t.Errorf("Unexpected failure for scenario, did not mismatch on mode when expected to mismatch: %s", name)
|
t.Errorf("Unexpected failure for scenario, did not mismatch on mode when expected to mismatch: %s", name)
|
||||||
}
|
}
|
||||||
recover()
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1252,7 +1253,8 @@ func TestFilteringVolumeModes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for name, scenario := range scenarios {
|
for name, scenario := range scenarios {
|
||||||
recover := utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, scenario.enableBlock)
|
t.Run(name, func(t *testing.T) {
|
||||||
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, scenario.enableBlock)()
|
||||||
pvmatch, err := scenario.vol.findBestMatchForClaim(scenario.pvc, false)
|
pvmatch, err := scenario.vol.findBestMatchForClaim(scenario.pvc, false)
|
||||||
// expected to match but either got an error or no returned pvmatch
|
// expected to match but either got an error or no returned pvmatch
|
||||||
if pvmatch == nil && scenario.isExpectedMatch {
|
if pvmatch == nil && scenario.isExpectedMatch {
|
||||||
@ -1268,7 +1270,7 @@ func TestFilteringVolumeModes(t *testing.T) {
|
|||||||
if err != nil && !scenario.isExpectedMatch {
|
if err != nil && !scenario.isExpectedMatch {
|
||||||
t.Errorf("Unexpected failure for scenario: %s - %+v", name, err)
|
t.Errorf("Unexpected failure for scenario: %s - %+v", name, err)
|
||||||
}
|
}
|
||||||
recover()
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,8 +274,7 @@ func TestResourceConfigForPodWithCustomCPUCFSQuotaPeriod(t *testing.T) {
|
|||||||
tunedQuotaPeriod := uint64(5 * time.Millisecond / time.Microsecond)
|
tunedQuotaPeriod := uint64(5 * time.Millisecond / time.Microsecond)
|
||||||
tunedQuota := int64(1 * time.Millisecond / time.Microsecond)
|
tunedQuota := int64(1 * time.Millisecond / time.Microsecond)
|
||||||
|
|
||||||
utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.CPUCFSQuotaPeriod, true)
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.CPUCFSQuotaPeriod, true)()
|
||||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, pkgfeatures.CPUCFSQuotaPeriod, false)
|
|
||||||
|
|
||||||
minShares := uint64(MinShares)
|
minShares := uint64(MinShares)
|
||||||
burstableShares := MilliCPUToShares(100)
|
burstableShares := MilliCPUToShares(100)
|
||||||
|
@ -89,8 +89,7 @@ func TestMilliCPUToQuota(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMilliCPUToQuotaWithCustomCPUCFSQuotaPeriod(t *testing.T) {
|
func TestMilliCPUToQuotaWithCustomCPUCFSQuotaPeriod(t *testing.T) {
|
||||||
utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CPUCFSQuotaPeriod, true)
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CPUCFSQuotaPeriod, true)()
|
||||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CPUCFSQuotaPeriod, false)
|
|
||||||
|
|
||||||
for _, testCase := range []struct {
|
for _, testCase := range []struct {
|
||||||
msg string
|
msg string
|
||||||
|
@ -351,8 +351,7 @@ func TestNamespacesForPod(t *testing.T) {
|
|||||||
assert.Equal(t, test.expected, actual)
|
assert.Equal(t, test.expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test ShareProcessNamespace feature disabled, feature gate restored by previous defer
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodShareProcessNamespace, false)()
|
||||||
utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodShareProcessNamespace, false)
|
|
||||||
|
|
||||||
for desc, test := range map[string]struct {
|
for desc, test := range map[string]struct {
|
||||||
input *v1.Pod
|
input *v1.Pod
|
||||||
|
Loading…
Reference in New Issue
Block a user