2016-10-17 17:23:48 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 2016 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 cm
|
|
|
|
|
2018-03-28 04:11:00 +00:00
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
)
|
2016-10-17 17:23:48 +00:00
|
|
|
|
2018-03-28 04:11:00 +00:00
|
|
|
func TestCgroupNameToSystemdBasename(t *testing.T) {
|
2016-10-17 17:23:48 +00:00
|
|
|
testCases := []struct {
|
2018-03-28 04:11:00 +00:00
|
|
|
input CgroupName
|
2016-10-17 17:23:48 +00:00
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: RootCgroupName,
|
|
|
|
expected: "/",
|
2016-10-17 17:23:48 +00:00
|
|
|
},
|
2017-02-20 17:03:58 +00:00
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "system"),
|
2017-02-20 17:03:58 +00:00
|
|
|
expected: "system.slice",
|
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "system", "Burstable"),
|
2017-02-20 17:03:58 +00:00
|
|
|
expected: "system-Burstable.slice",
|
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "Burstable", "pod-123"),
|
2017-02-20 17:03:58 +00:00
|
|
|
expected: "Burstable-pod_123.slice",
|
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "test", "a", "b"),
|
2017-02-20 17:03:58 +00:00
|
|
|
expected: "test-a-b.slice",
|
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "test", "a", "b", "Burstable"),
|
2017-02-20 17:03:58 +00:00
|
|
|
expected: "test-a-b-Burstable.slice",
|
|
|
|
},
|
2016-10-17 17:23:48 +00:00
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "Burstable"),
|
2016-10-17 17:23:48 +00:00
|
|
|
expected: "Burstable.slice",
|
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "BestEffort", "pod-6c1a4e95-6bb6-11e6-bc26-28d2444e470d"),
|
2016-10-17 17:23:48 +00:00
|
|
|
expected: "BestEffort-pod_6c1a4e95_6bb6_11e6_bc26_28d2444e470d.slice",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
2018-03-28 04:11:00 +00:00
|
|
|
if actual := path.Base(testCase.input.ToSystemd()); actual != testCase.expected {
|
2016-10-17 17:23:48 +00:00
|
|
|
t.Errorf("Unexpected result, input: %v, expected: %v, actual: %v", testCase.input, testCase.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 04:11:00 +00:00
|
|
|
func TestCgroupNameToSystemd(t *testing.T) {
|
2016-10-17 17:23:48 +00:00
|
|
|
testCases := []struct {
|
2018-03-28 04:11:00 +00:00
|
|
|
input CgroupName
|
2016-10-17 17:23:48 +00:00
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: RootCgroupName,
|
2016-10-17 17:23:48 +00:00
|
|
|
expected: "/",
|
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "Burstable"),
|
2018-02-20 19:09:01 +00:00
|
|
|
expected: "/Burstable.slice",
|
2016-10-17 17:23:48 +00:00
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "Burstable", "pod-123"),
|
2018-02-20 19:09:01 +00:00
|
|
|
expected: "/Burstable.slice/Burstable-pod_123.slice",
|
2016-10-17 17:23:48 +00:00
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "BestEffort", "pod-6c1a4e95-6bb6-11e6-bc26-28d2444e470d"),
|
2018-02-20 19:09:01 +00:00
|
|
|
expected: "/BestEffort.slice/BestEffort-pod_6c1a4e95_6bb6_11e6_bc26_28d2444e470d.slice",
|
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "kubepods"),
|
2018-02-20 19:09:01 +00:00
|
|
|
expected: "/kubepods.slice",
|
2016-10-17 17:23:48 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
2018-03-28 04:11:00 +00:00
|
|
|
if actual := testCase.input.ToSystemd(); actual != testCase.expected {
|
2016-10-17 17:23:48 +00:00
|
|
|
t.Errorf("Unexpected result, input: %v, expected: %v, actual: %v", testCase.input, testCase.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 06:14:59 +00:00
|
|
|
|
2018-03-28 04:11:00 +00:00
|
|
|
func TestCgroupNameToCgroupfs(t *testing.T) {
|
2017-11-30 06:14:59 +00:00
|
|
|
testCases := []struct {
|
2018-03-28 04:11:00 +00:00
|
|
|
input CgroupName
|
2017-11-30 06:14:59 +00:00
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: RootCgroupName,
|
2017-11-30 06:14:59 +00:00
|
|
|
expected: "/",
|
|
|
|
},
|
|
|
|
{
|
2018-03-28 04:11:00 +00:00
|
|
|
input: NewCgroupName(RootCgroupName, "Burstable"),
|
2017-11-30 06:14:59 +00:00
|
|
|
expected: "/Burstable",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
2018-03-28 04:11:00 +00:00
|
|
|
if actual := testCase.input.ToCgroupfs(); actual != testCase.expected {
|
2017-11-30 06:14:59 +00:00
|
|
|
t.Errorf("Unexpected result, input: %v, expected: %v, actual: %v", testCase.input, testCase.expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|