github.com/gobuffalo/buffalo-cli/v2@v2.0.0-alpha.15.0.20200919213536-a7350c8e6799/cli/cmds/test/main_test.go (about) 1 package test 2 3 import ( 4 "context" 5 "os/exec" 6 "strings" 7 "testing" 8 9 "github.com/gobuffalo/plugins" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func cmpCmd(t *testing.T, exp string, cmd *exec.Cmd) { 14 t.Helper() 15 act := strings.Join(cmd.Args, " ") 16 if act != exp { 17 t.Fatalf("expected '%s', got '%s'", exp, act) 18 } 19 } 20 21 func Test_Cmd_Cmd(t *testing.T) { 22 r := require.New(t) 23 24 ctx := context.Background() 25 args := []string{} 26 27 tc := &Cmd{} 28 29 cmd, err := tc.Cmd(ctx, ".", args) 30 r.NoError(err) 31 32 cmpCmd(t, "go test ./...", cmd) 33 } 34 35 func Test_Cmd_Cmd_paths(t *testing.T) { 36 r := require.New(t) 37 38 ctx := context.Background() 39 args := []string{} 40 41 tc := &Cmd{} 42 43 cmd, err := tc.Cmd(ctx, ".", args) 44 r.NoError(err) 45 46 cmpCmd(t, "go test ./...", cmd) 47 48 args = append(args, "-v") 49 50 cmd, err = tc.Cmd(ctx, ".", args) 51 r.NoError(err) 52 53 cmpCmd(t, "go test -v ./...", cmd) 54 55 args = append(args, "./a") 56 57 cmd, err = tc.Cmd(ctx, ".", args) 58 r.NoError(err) 59 60 cmpCmd(t, "go test -v ./a", cmd) 61 } 62 63 func Test_Cmd_Cmd_buildArgs(t *testing.T) { 64 r := require.New(t) 65 66 ctx := context.Background() 67 args := []string{"-tags", "you're"} 68 69 tc := &Cmd{} 70 71 cmd, err := tc.Cmd(ctx, ".", args) 72 r.NoError(err) 73 74 cmpCmd(t, "go test -tags you're ./...", cmd) 75 76 args = append(args, "-run", "Foo", "-tags", "it", "-v", "./...") 77 78 cmd, err = tc.Cmd(ctx, ".", args) 79 r.NoError(err) 80 81 cmpCmd(t, "go test -tags you're it -run Foo -v ./...", cmd) 82 83 tc.WithPlugins(func() []plugins.Plugin { 84 return []plugins.Plugin{ 85 &tagger{ 86 tags: []string{"-tags", "i", "-failfast"}, 87 }, 88 } 89 }) 90 91 cmd, err = tc.Cmd(ctx, ".", args) 92 r.NoError(err) 93 cmpCmd(t, "go test -tags i you're it -failfast -run Foo -v ./...", cmd) 94 }