This repository has been archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #494 from Mashimiao/return-clear-freezer-error
cgroups: reurn error when passing invalid argument to freezer
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |