Skip to content

Commit

Permalink
Make hooks test validation work as expected
Browse files Browse the repository at this point in the history
Read output file before it is deleted and update the assertion text to
match the executed hooks.

Signed-off-by: nixpig <143995476+nixpig@users.noreply.github.com>
  • Loading branch information
nixpig committed Nov 27, 2024
1 parent f7e3563 commit d698e6a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions validation/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ func main() {
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second)
return nil
},
PostDelete: func(r *util.Runtime) error {
outputData, err := os.ReadFile(output)
if err != nil || string(outputData) != "pre-start1 called\npre-start2 called\npost-start1 called\npost-start2 called\npost-stop1 called\npost-stop2 called\n" {
return fmt.Errorf("%v\n%v", specerror.NewError(specerror.PosixHooksCalledInOrder, fmt.Errorf("Hooks MUST be called in the listed order"), rspec.Version), specerror.NewError(specerror.ProcImplement, fmt.Errorf("The runtime MUST run the user-specified program, as specified by `process`"), rspec.Version))
}
return nil
},
}

err := util.RuntimeLifecycleValidate(config)
outputData, _ := os.ReadFile(output)
if err == nil && string(outputData) != "pre-start1 called\npre-start2 called\npost-start1\npost-start2\npost-stop1\npost-stop2\n" {
err = specerror.NewError(specerror.PosixHooksCalledInOrder, fmt.Errorf("Hooks MUST be called in the listed order"), rspec.Version)
diagnostic := map[string]string{
"error": err.Error(),
}
_ = t.YAML(diagnostic)
} else {
if err != nil {
diagnostic := map[string]string{
"error": err.Error(),
}
Expand Down

0 comments on commit d698e6a

Please sign in to comment.