Skip to content

Commit d698e6a

Browse files
committed
Make hooks test validation work as expected
Read output file before it is deleted and update the assertion text to match the executed hooks. Signed-off-by: nixpig <[email protected]>
1 parent f7e3563 commit d698e6a

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

validation/hooks/hooks.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ func main() {
7272
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second)
7373
return nil
7474
},
75+
PostDelete: func(r *util.Runtime) error {
76+
outputData, err := os.ReadFile(output)
77+
if err != nil || string(outputData) != "pre-start1 called\npre-start2 called\npost-start1 called\npost-start2 called\npost-stop1 called\npost-stop2 called\n" {
78+
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))
79+
}
80+
return nil
81+
},
7582
}
7683

7784
err := util.RuntimeLifecycleValidate(config)
78-
outputData, _ := os.ReadFile(output)
79-
if err == nil && string(outputData) != "pre-start1 called\npre-start2 called\npost-start1\npost-start2\npost-stop1\npost-stop2\n" {
80-
err = specerror.NewError(specerror.PosixHooksCalledInOrder, fmt.Errorf("Hooks MUST be called in the listed order"), rspec.Version)
81-
diagnostic := map[string]string{
82-
"error": err.Error(),
83-
}
84-
_ = t.YAML(diagnostic)
85-
} else {
85+
if err != nil {
8686
diagnostic := map[string]string{
8787
"error": err.Error(),
8888
}

0 commit comments

Comments
 (0)