Skip to content

Commit

Permalink
check the status of the state passed to hooks over stdin
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Chenye <liangchenye@huawei.com>
  • Loading branch information
liangchenye committed Mar 19, 2018
1 parent b3796e2 commit dd55168
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions validation/hooks_stdin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ func stdinStateCheck(outputDir, hookName string, expectedState rspecs.State) err
if !reflect.DeepEqual(state.Annotations, expectedState.Annotations) {
return fmt.Errorf("wrong annotations \"%v\" in the stdin of %s hook, expected \"%v\"", state.Annotations, hookName, expectedState.Annotations)
}

switch hookName {
case "prestart":
if state.Status != "created" {
return fmt.Errorf("wrong state %q in the stdin of %s hook, expected %q", state.Status, hookName, "created")
}
case "poststart":
if state.Status != "running" {
return fmt.Errorf("wrong state %q in the stdin of %s hook, expected %q", state.Status, hookName, "running")
}
case "poststop":
// Not defined by runtime spec
default:
return fmt.Errorf("internal error, unexpected hook name %q", hookName)
}

return nil
}

Expand Down

0 comments on commit dd55168

Please sign in to comment.