From d698e6ac4eb70cac025979549d434be4bf536c4d Mon Sep 17 00:00:00 2001 From: nixpig <143995476+nixpig@users.noreply.github.com> Date: Wed, 27 Nov 2024 05:48:24 +0000 Subject: [PATCH] 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 <143995476+nixpig@users.noreply.github.com> --- validation/hooks/hooks.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/validation/hooks/hooks.go b/validation/hooks/hooks.go index f039a073..e5349d77 100644 --- a/validation/hooks/hooks.go +++ b/validation/hooks/hooks.go @@ -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(), }