From ec058b14f0bb73dd0de7cdb07a2e6d0d13f5ba79 Mon Sep 17 00:00:00 2001 From: wackxu Date: Sun, 10 Sep 2017 16:53:15 +0800 Subject: [PATCH] add some test case --- .../algorithmprovider/defaults/BUILD | 1 + .../defaults/defaults_test.go | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/plugin/pkg/scheduler/algorithmprovider/defaults/BUILD b/plugin/pkg/scheduler/algorithmprovider/defaults/BUILD index e5fdf33f0ac..f2357cd6c85 100644 --- a/plugin/pkg/scheduler/algorithmprovider/defaults/BUILD +++ b/plugin/pkg/scheduler/algorithmprovider/defaults/BUILD @@ -39,6 +39,7 @@ go_test( "//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library", + "//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library", "//vendor/k8s.io/client-go/informers:go_default_library", "//vendor/k8s.io/client-go/kubernetes:go_default_library", "//vendor/k8s.io/client-go/rest:go_default_library", diff --git a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults_test.go b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults_test.go index c6c4400fa86..fb5f4d249d8 100644 --- a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults_test.go +++ b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults_test.go @@ -17,6 +17,8 @@ limitations under the License. package defaults import ( + "k8s.io/apimachinery/pkg/util/sets" + utilfeature "k8s.io/apiserver/pkg/util/feature" "os" "testing" ) @@ -60,3 +62,95 @@ func TestGetMaxVols(t *testing.T) { os.Setenv(KubeMaxPDVols, previousValue) } } + +func TestCopyAndReplace(t *testing.T) { + testCases := []struct { + set sets.String + replaceWhat string + replaceWith string + expected sets.String + }{ + { + set: sets.String{"A": sets.Empty{}, "B": sets.Empty{}}, + replaceWhat: "A", + replaceWith: "C", + expected: sets.String{"B": sets.Empty{}, "C": sets.Empty{}}, + }, + { + set: sets.String{"A": sets.Empty{}, "B": sets.Empty{}}, + replaceWhat: "D", + replaceWith: "C", + expected: sets.String{"A": sets.Empty{}, "B": sets.Empty{}}, + }, + } + for _, testCase := range testCases { + result := copyAndReplace(testCase.set, testCase.replaceWhat, testCase.replaceWith) + if !result.Equal(testCase.expected) { + t.Errorf("expected %v got %v", testCase.expected, result) + } + } +} + +func TestDefaultPriorities(t *testing.T) { + result := sets.NewString( + "SelectorSpreadPriority", + "InterPodAffinityPriority", + "LeastRequestedPriority", + "BalancedResourceAllocation", + "NodePreferAvoidPodsPriority", + "NodeAffinityPriority", + "TaintTolerationPriority") + if expected := defaultPriorities(); !result.Equal(expected) { + t.Errorf("expected %v got %v", expected, result) + } +} + +func TestDefaultPredicates(t *testing.T) { + testCases := []struct { + actionFunc func(value string) error + actionParam string + expected sets.String + }{ + { + actionFunc: utilfeature.DefaultFeatureGate.Set, + actionParam: "TaintNodesByCondition=true", + expected: sets.NewString( + "NoVolumeZoneConflict", + "MaxEBSVolumeCount", + "MaxGCEPDVolumeCount", + "MaxAzureDiskVolumeCount", + "MatchInterPodAffinity", + "NoDiskConflict", + "GeneralPredicates", + "CheckNodeMemoryPressure", + "CheckNodeDiskPressure", + "NoVolumeNodeConflict", + "PodToleratesNodeTaints", + ), + }, + { + actionFunc: utilfeature.DefaultFeatureGate.Set, + actionParam: "TaintNodesByCondition=false", + expected: sets.NewString( + "NoVolumeZoneConflict", + "MaxEBSVolumeCount", + "MaxGCEPDVolumeCount", + "MaxAzureDiskVolumeCount", + "MatchInterPodAffinity", + "NoDiskConflict", + "GeneralPredicates", + "CheckNodeMemoryPressure", + "CheckNodeDiskPressure", + "NoVolumeNodeConflict", + "CheckNodeCondition", + "PodToleratesNodeTaints", + ), + }, + } + for _, testCase := range testCases { + testCase.actionFunc(testCase.actionParam) + if result := defaultPredicates(); !result.Equal(testCase.expected) { + t.Errorf("expected %v got %v", testCase.expected, result) + } + } +}