mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 11:28:58 +00:00
node: topologymanager: don't leak options in tests
unit tests for the policy options add test options to the global state without proper cleanup; this is done only in tests so it has limited room for doing damage, but still weakens the test signal. Let's avoid that adding proper cleanup. Signed-off-by: Francesco Romani <fromani@redhat.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/component-base/featuregate"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
@@ -141,8 +142,8 @@ func TestNewTopologyManagerOptions(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
betaOptions.Insert(fancyBetaOption)
|
||||
alphaOptions.Insert(fancyAlphaOption)
|
||||
setTopologyManagerOptionsDuringTest(t, betaOptions, fancyBetaOption)
|
||||
setTopologyManagerOptionsDuringTest(t, alphaOptions, fancyAlphaOption)
|
||||
|
||||
logger, _ := ktesting.NewTestContext(t)
|
||||
|
||||
@@ -166,6 +167,14 @@ func TestNewTopologyManagerOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func setTopologyManagerOptionsDuringTest(t *testing.T, optionGroup sets.Set[string], opts ...string) {
|
||||
t.Helper()
|
||||
t.Cleanup(func() {
|
||||
optionGroup.Delete(opts...)
|
||||
})
|
||||
optionGroup.Insert(opts...)
|
||||
}
|
||||
|
||||
func TestPolicyDefaultsAvailable(t *testing.T) {
|
||||
testCases := []optionAvailTest{
|
||||
{
|
||||
@@ -243,8 +252,8 @@ func TestPolicyOptionsAvailable(t *testing.T) {
|
||||
expectedAvailable: false,
|
||||
},
|
||||
}
|
||||
betaOptions.Insert(fancyBetaOption)
|
||||
alphaOptions.Insert(fancyAlphaOption)
|
||||
setTopologyManagerOptionsDuringTest(t, betaOptions, fancyBetaOption)
|
||||
setTopologyManagerOptionsDuringTest(t, alphaOptions, fancyAlphaOption)
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.option, func(t *testing.T) {
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, testCase.featureGate, testCase.featureGateEnable)
|
||||
|
||||
Reference in New Issue
Block a user