Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #494 from Mashimiao/return-clear-freezer-error
Browse files Browse the repository at this point in the history
cgroups: reurn error when passing invalid argument to freezer
  • Loading branch information
Mrunal Patel committed Mar 31, 2015
2 parents c851275 + 0eb8a1a commit 1a246dd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cgroups/fs/freezer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fs

import (
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -41,6 +42,10 @@ func (s *FreezerGroup) Set(path string, cgroup *configs.Cgroup) error {
}
time.Sleep(1 * time.Millisecond)
}
case configs.Undefined:
return nil
default:
return fmt.Errorf("Invalid argument '%s' to freezer.state", string(cgroup.Freezer))
}

return nil
Expand Down
45 changes: 45 additions & 0 deletions cgroups/fs/freezer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package fs

import (
"testing"

"github.com/docker/libcontainer/configs"
)

func TestFreezerSetState(t *testing.T) {
helper := NewCgroupTestUtil("freezer", t)
defer helper.cleanup()

helper.writeFileContents(map[string]string{
"freezer.state": string(configs.Frozen),
})

helper.CgroupData.c.Freezer = configs.Thawed
freezer := &FreezerGroup{}
if err := freezer.Set(helper.CgroupPath, helper.CgroupData.c); err != nil {
t.Fatal(err)
}

value, err := getCgroupParamString(helper.CgroupPath, "freezer.state")
if err != nil {
t.Fatalf("Failed to parse freezer.state - %s", err)
}
if value != string(configs.Thawed) {
t.Fatal("Got the wrong value, set freezer.state failed.")
}
}

func TestFreezerSetInvalidState(t *testing.T) {
helper := NewCgroupTestUtil("freezer", t)
defer helper.cleanup()

const (
invalidArg configs.FreezerState = "Invalid"
)

helper.CgroupData.c.Freezer = invalidArg
freezer := &FreezerGroup{}
if err := freezer.Set(helper.CgroupPath, helper.CgroupData.c); err == nil {
t.Fatal("Failed to return invalid argument error")
}
}

0 comments on commit 1a246dd

Please sign in to comment.