-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.go
40 lines (35 loc) · 1.06 KB
/
hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"github.com/chakrit/smoke/checks"
"github.com/chakrit/smoke/engine"
"github.com/chakrit/smoke/internal/p"
)
type Hooks struct {
WrapErr func(t *engine.Test, err error) error
}
var _ engine.RunHooks = Hooks{}
func (h Hooks) BeforeTest(t *engine.Test) {
p.Test(t)
}
func (h Hooks) BeforeCommand(t *engine.Test, cmd engine.Command) {
p.Command(t, cmd)
}
func (h Hooks) BeforeCheck(t *engine.Test, cmd engine.Command, chk checks.Interface) {
p.Check(t, cmd, chk)
}
func (h Hooks) AfterCheck(t *engine.Test, cmd engine.Command, chk checks.Interface, result checks.Result, err error) {
p.CheckResult(result, h.wrapErr(t, err))
}
func (h Hooks) AfterCommand(t *engine.Test, cmd engine.Command, result engine.CommandResult, err error) {
p.CommandResult(result, h.wrapErr(t, err))
}
func (h Hooks) AfterTest(t *engine.Test, result engine.TestResult, err error) {
p.TestResult(result, h.wrapErr(t, err))
}
func (h Hooks) wrapErr(t *engine.Test, err error) error {
if err != nil && h.WrapErr != nil {
return h.WrapErr(t, err)
} else {
return err
}
}