github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/standard/tester.go (about) 1 package standard 2 3 import ( 4 "context" 5 "os" 6 "os/exec" 7 "strings" 8 9 "github.com/wawandco/oxpecker/internal/log" 10 ) 11 12 type Tester struct{} 13 14 func (t Tester) Name() string { 15 return "standard/tester" 16 } 17 18 func (b *Tester) RunBeforeTest(ctx context.Context, root string, args []string) error { 19 return os.Setenv("GO_ENV", "test") 20 } 21 22 func (p *Tester) Test(ctx context.Context, root string, args []string) error { 23 log.Info("running tests") 24 25 cmd := exec.CommandContext(ctx, "go", p.testArgs(args)...) 26 cmd.Stdin = os.Stdin 27 cmd.Stdout = os.Stdout 28 cmd.Stderr = os.Stderr 29 30 log.Infof("Running Command: %v\n", strings.Join(cmd.Args, " ")) 31 32 return cmd.Run() 33 } 34 35 func (p *Tester) testArgs(args []string) []string { 36 base := []string{ 37 "test", 38 } 39 40 if !strings.Contains(strings.Join(args, " "), "-p") { 41 base = append(base, "-p", "1") 42 } 43 44 cargs := append(base, "./...") 45 if len(args) > 0 { 46 cargs = append(base, args...) 47 } 48 49 return cargs 50 }