Move cgroups package into libcontainer

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-05-14 15:21:44 -07:00
parent 9133caa6d3
commit b30f280d2f
25 changed files with 15 additions and 13 deletions

View file

@ -0,0 +1,57 @@
package fs
import (
"testing"
)
func TestCpuStats(t *testing.T) {
helper := NewCgroupTestUtil("cpu", t)
defer helper.cleanup()
cpuStatContent := `nr_periods 2000
nr_throttled 200
throttled_time 42424242424`
helper.writeFileContents(map[string]string{
"cpu.stat": cpuStatContent,
})
cpu := &cpuGroup{}
stats, err := cpu.Stats(helper.CgroupData)
if err != nil {
t.Fatal(err)
}
expected_stats := map[string]float64{
"nr_periods": 2000.0,
"nr_throttled": 200.0,
"throttled_time": 42424242424.0,
}
expectStats(t, expected_stats, stats)
}
func TestNoCpuStatFile(t *testing.T) {
helper := NewCgroupTestUtil("cpu", t)
defer helper.cleanup()
cpu := &cpuGroup{}
_, err := cpu.Stats(helper.CgroupData)
if err == nil {
t.Fatal("Expected to fail, but did not.")
}
}
func TestInvalidCpuStat(t *testing.T) {
helper := NewCgroupTestUtil("cpu", t)
defer helper.cleanup()
cpuStatContent := `nr_periods 2000
nr_throttled 200
throttled_time fortytwo`
helper.writeFileContents(map[string]string{
"cpu.stat": cpuStatContent,
})
cpu := &cpuGroup{}
_, err := cpu.Stats(helper.CgroupData)
if err == nil {
t.Fatal("Expected failed stat parsing.")
}
}