2023-01-09 12:16:23 +00:00
|
|
|
/*
|
|
|
|
Copyright 2023 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package topologypolicy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-02-07 15:48:01 +00:00
|
|
|
"github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2"
|
2023-01-09 12:16:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDetectTopologyPolicy(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
scope string
|
|
|
|
policy string
|
2023-02-07 15:48:01 +00:00
|
|
|
expected v1alpha2.TopologyManagerPolicy
|
2023-01-09 12:16:23 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
policy: "best-effort",
|
|
|
|
scope: "pod",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.BestEffortPodLevel,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "best-effort",
|
|
|
|
scope: "container",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.BestEffortContainerLevel,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "restricted",
|
|
|
|
scope: "container",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.RestrictedContainerLevel,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "restricted",
|
|
|
|
scope: "pod",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.RestrictedPodLevel,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "single-numa-node",
|
|
|
|
scope: "pod",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.SingleNUMANodePodLevel,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "single-numa-node",
|
|
|
|
scope: "container",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.SingleNUMANodeContainerLevel,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "none",
|
|
|
|
scope: "container",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.None,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "none",
|
|
|
|
scope: "pod",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.None,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "non-existent",
|
|
|
|
scope: "pod",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.None,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "non-existent",
|
|
|
|
scope: "container",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.None,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "single-numa-node",
|
|
|
|
scope: "non-existent",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.None,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
policy: "single-numa-node",
|
|
|
|
scope: "non-existent",
|
2023-02-07 15:48:01 +00:00
|
|
|
expected: v1alpha2.None,
|
2023-01-09 12:16:23 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
actual := DetectTopologyPolicy(tc.policy, tc.scope)
|
|
|
|
if actual != tc.expected {
|
|
|
|
t.Errorf("Expected TopologyPolicy to equal: %s not: %s", tc.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|