Skip to content

Commit

Permalink
Merge pull request #1410 from chchliang/statustest
Browse files Browse the repository at this point in the history
add createdState and runningState status testcase
  • Loading branch information
hqhq authored May 12, 2017
2 parents 2daa115 + 4f0e6c4 commit 21ef2e3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions libcontainer/state_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,40 @@ func TestRestoredStateTransition(t *testing.T) {
t.Fatal("expected stateTransitionError")
}
}

func TestRunningStateTransition(t *testing.T) {
s := &runningState{c: &linuxContainer{}}
valid := []containerState{
&stoppedState{},
&pausedState{},
&runningState{},
}
for _, v := range valid {
if err := s.transition(v); err != nil {
t.Fatal(err)
}
}

err := s.transition(&createdState{})
if err == nil {
t.Fatal("transition to created state should fail")
}
if !isStateTransitionError(err) {
t.Fatal("expected stateTransitionError")
}
}

func TestCreatedStateTransition(t *testing.T) {
s := &createdState{c: &linuxContainer{}}
valid := []containerState{
&stoppedState{},
&pausedState{},
&runningState{},
&createdState{},
}
for _, v := range valid {
if err := s.transition(v); err != nil {
t.Fatal(err)
}
}
}

0 comments on commit 21ef2e3

Please sign in to comment.