mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 08:40:42 +00:00
Update topologymanager tests after adding scopes
Signed-off-by: Krzysztof Wiatrzyk <k.wiatrzyk@samsung.com>
This commit is contained in:
parent
9da0912a33
commit
f5c0fe4ef6
@ -75,8 +75,6 @@ func TestFakeAddContainer(t *testing.T) {
|
||||
},
|
||||
}
|
||||
fm := fakeManager{}
|
||||
mngr := manager{}
|
||||
mngr.podMap = make(map[string]string)
|
||||
for _, tc := range testCases {
|
||||
pod := v1.Pod{}
|
||||
pod.UID = tc.podUID
|
||||
@ -107,8 +105,6 @@ func TestFakeRemoveContainer(t *testing.T) {
|
||||
},
|
||||
}
|
||||
fm := fakeManager{}
|
||||
mngr := manager{}
|
||||
mngr.podMap = make(map[string]string)
|
||||
for _, tc := range testCases {
|
||||
err := fm.RemoveContainer(tc.containerID)
|
||||
if err != nil {
|
||||
@ -147,8 +143,6 @@ func TestFakeAdmit(t *testing.T) {
|
||||
}
|
||||
fm := fakeManager{}
|
||||
for _, tc := range tcases {
|
||||
mngr := manager{}
|
||||
mngr.podTopologyHints = make(map[string]map[string]TopologyHint)
|
||||
podAttr := lifecycle.PodAdmitAttributes{}
|
||||
pod := v1.Pod{}
|
||||
pod.Status.QOSClass = tc.qosClass
|
||||
|
@ -40,6 +40,11 @@ func TestNewManager(t *testing.T) {
|
||||
expectedPolicy string
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
description: "Policy is set to none",
|
||||
policyName: "none",
|
||||
expectedPolicy: "none",
|
||||
},
|
||||
{
|
||||
description: "Policy is set to best-effort",
|
||||
policyName: "best-effort",
|
||||
@ -50,6 +55,11 @@ func TestNewManager(t *testing.T) {
|
||||
policyName: "restricted",
|
||||
expectedPolicy: "restricted",
|
||||
},
|
||||
{
|
||||
description: "Policy is set to single-numa-node",
|
||||
policyName: "single-numa-node",
|
||||
expectedPolicy: "single-numa-node",
|
||||
},
|
||||
{
|
||||
description: "Policy is set to unknown",
|
||||
policyName: "unknown",
|
||||
@ -58,7 +68,7 @@ func TestNewManager(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range tcases {
|
||||
mngr, err := NewManager(nil, tc.policyName)
|
||||
mngr, err := NewManager(nil, tc.policyName, "container")
|
||||
|
||||
if tc.expectedError != nil {
|
||||
if !strings.Contains(err.Error(), tc.expectedError.Error()) {
|
||||
@ -66,8 +76,49 @@ func TestNewManager(t *testing.T) {
|
||||
}
|
||||
} else {
|
||||
rawMgr := mngr.(*manager)
|
||||
if rawMgr.policy.Name() != tc.expectedPolicy {
|
||||
t.Errorf("Unexpected policy name. Have: %q wants %q", rawMgr.policy.Name(), tc.expectedPolicy)
|
||||
rawScope := rawMgr.scope.(*containerScope)
|
||||
if rawScope.policy.Name() != tc.expectedPolicy {
|
||||
t.Errorf("Unexpected policy name. Have: %q wants %q", rawScope.policy.Name(), tc.expectedPolicy)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagerScope(t *testing.T) {
|
||||
tcases := []struct {
|
||||
description string
|
||||
scopeName string
|
||||
expectedScope string
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
description: "Topology Manager Scope is set to container",
|
||||
scopeName: "container",
|
||||
expectedScope: "container",
|
||||
},
|
||||
{
|
||||
description: "Topology Manager Scope is set to pod",
|
||||
scopeName: "pod",
|
||||
expectedScope: "pod",
|
||||
},
|
||||
{
|
||||
description: "Topology Manager Scope is set to unknown",
|
||||
scopeName: "unknown",
|
||||
expectedError: fmt.Errorf("unknown scope: \"unknown\""),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tcases {
|
||||
mngr, err := NewManager(nil, "best-effort", tc.scopeName)
|
||||
|
||||
if tc.expectedError != nil {
|
||||
if !strings.Contains(err.Error(), tc.expectedError.Error()) {
|
||||
t.Errorf("Unexpected error message. Have: %s wants %s", err.Error(), tc.expectedError.Error())
|
||||
}
|
||||
} else {
|
||||
rawMgr := mngr.(*manager)
|
||||
if rawMgr.scope.Name() != tc.expectedScope {
|
||||
t.Errorf("Unexpected scope name. Have: %q wants %q", rawMgr.scope, tc.expectedScope)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -434,7 +485,6 @@ func TestRemoveContainer(t *testing.T) {
|
||||
|
||||
}
|
||||
func TestAddHintProvider(t *testing.T) {
|
||||
var len1 int
|
||||
tcases := []struct {
|
||||
name string
|
||||
hp []HintProvider
|
||||
@ -443,19 +493,21 @@ func TestAddHintProvider(t *testing.T) {
|
||||
name: "Add HintProvider",
|
||||
hp: []HintProvider{
|
||||
&mockHintProvider{},
|
||||
&mockHintProvider{},
|
||||
&mockHintProvider{},
|
||||
},
|
||||
},
|
||||
}
|
||||
mngr := manager{}
|
||||
mngr.scope = NewContainerScope(NewNonePolicy())
|
||||
for _, tc := range tcases {
|
||||
mngr.hintProviders = []HintProvider{}
|
||||
len1 = len(mngr.hintProviders)
|
||||
mngr.AddHintProvider(tc.hp[0])
|
||||
for _, hp := range tc.hp {
|
||||
mngr.AddHintProvider(hp)
|
||||
}
|
||||
len2 := len(mngr.hintProviders)
|
||||
if len2-len1 != 1 {
|
||||
if len(tc.hp) != len(mngr.scope.(*containerScope).hintProviders) {
|
||||
t.Errorf("error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdmit(t *testing.T) {
|
||||
@ -727,11 +779,13 @@ func TestAdmit(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, tc := range tcases {
|
||||
man := manager{
|
||||
policy: tc.policy,
|
||||
podTopologyHints: make(map[string]map[string]TopologyHint),
|
||||
hintProviders: tc.hp,
|
||||
}
|
||||
ctnScopeManager := manager{}
|
||||
ctnScopeManager.scope = NewContainerScope(tc.policy)
|
||||
ctnScopeManager.scope.(*containerScope).hintProviders = tc.hp
|
||||
|
||||
podScopeManager := manager{}
|
||||
podScopeManager.scope = NewPodScope(tc.policy)
|
||||
podScopeManager.scope.(*podScope).hintProviders = tc.hp
|
||||
|
||||
pod := &v1.Pod{
|
||||
Spec: v1.PodSpec{
|
||||
@ -750,9 +804,16 @@ func TestAdmit(t *testing.T) {
|
||||
Pod: pod,
|
||||
}
|
||||
|
||||
actual := man.Admit(&podAttr)
|
||||
if actual.Admit != tc.expected {
|
||||
t.Errorf("Error occurred, expected Admit in result to be %v got %v", tc.expected, actual.Admit)
|
||||
// Container scope Admit
|
||||
ctnActual := ctnScopeManager.Admit(&podAttr)
|
||||
if ctnActual.Admit != tc.expected {
|
||||
t.Errorf("Error occurred, expected Admit in result to be %v got %v", tc.expected, ctnActual.Admit)
|
||||
}
|
||||
|
||||
// Pod scope Admit
|
||||
podActual := podScopeManager.Admit(&podAttr)
|
||||
if podActual.Admit != tc.expected {
|
||||
t.Errorf("Error occurred, expected Admit in result to be %v got %v", tc.expected, podActual.Admit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user