github.com/wawandco/oxplugins@v0.7.11/lifecycle/test/command.go (about) 1 // test package contains the tooling for the test 2 // command on the cli. The goal of this package is to provide the 3 // structure for test commands to run and be organized. 4 package test 5 6 import ( 7 "context" 8 "fmt" 9 10 "github.com/wawandco/oxplugins/plugins" 11 ) 12 13 var _ plugins.Plugin = (*Command)(nil) 14 var _ plugins.PluginReceiver = (*Command)(nil) 15 var _ plugins.Command = (*Command)(nil) 16 17 type Command struct { 18 beforeTesters []BeforeTester 19 testers []Tester 20 afterTesters []AfterTester 21 } 22 23 func (c Command) Name() string { 24 return "test" 25 } 26 27 func (c Command) ParentName() string { 28 return "" 29 } 30 31 func (c Command) HelpText() string { 32 return "provides the structure for test commands to run and be organized" 33 } 34 35 func (c *Command) Run(ctx context.Context, root string, args []string) error { 36 var err error 37 for _, bt := range c.beforeTesters { 38 err = bt.RunBeforeTest(ctx, root, args[1:]) 39 if err != nil { 40 fmt.Printf("[warning] Error running %v before tester: %v\n", bt.Name(), err) 41 break 42 } 43 } 44 45 if err == nil { 46 for _, tt := range c.testers { 47 err = tt.Test(ctx, root, args[1:]) 48 if err != nil { 49 break 50 } 51 } 52 } 53 54 for _, at := range c.afterTesters { 55 err := at.RunAfterTest(ctx, root, args[1:]) 56 if err != nil { 57 fmt.Printf("error running %v after tester: %v\n", at.Name(), err) 58 } 59 } 60 61 return err 62 }