github.com/wawandco/ox@v0.13.6-0.20230809142027-913b3d837f2a/cli/cli_integration_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package cli_test 5 6 import ( 7 "bytes" 8 "context" 9 "os" 10 "os/exec" 11 "path/filepath" 12 "testing" 13 14 "github.com/wawandco/ox/cli" 15 "github.com/wawandco/ox/internal/testhelpers" 16 ) 17 18 func TestNewApp(t *testing.T) { 19 t.Run("NewAppOk", func(tt *testing.T) { 20 testhelpers.WithinTempDir(tt, func(t *testing.T, dir string) { 21 err := cli.Run(context.Background(), []string{"ox", "new", "coke", "-f"}) 22 if err != nil { 23 t.Fatalf("error running new command: %v", err) 24 } 25 26 specs := testhelpers.FileSpecs{ 27 { 28 Path: filepath.Join(dir, "coke"), 29 Condition: testhelpers.ConditionExists, 30 }, 31 { 32 Path: filepath.Join(dir, "coke", "go.mod"), 33 Condition: testhelpers.ConditionExists, 34 }, 35 { 36 Path: filepath.Join(dir, "coke", "go.sum"), 37 Condition: testhelpers.ConditionExists, 38 }, 39 } 40 41 specs.CheckAll(t) 42 }) 43 }) 44 45 t.Run("FolderExists", func(tt *testing.T) { 46 testhelpers.WithinTempDir(tt, func(t *testing.T, dir string) { 47 err := os.MkdirAll(filepath.Join(dir, "coke"), 0644) 48 if err != nil { 49 t.Fatalf("error creating folder: %v", err) 50 } 51 52 err = cli.Run(context.Background(), []string{"ox", "new", "coke"}) 53 if err == nil { 54 t.Fatalf("expected error running new command with folder existing") 55 } 56 }) 57 }) 58 59 } 60 61 func TestNoCommand(t *testing.T) { 62 cmd := exec.Command("go", "install", "github.com/wawandco/ox/cmd/ox") 63 cmd.Stdout = os.Stdout 64 cmd.Stderr = os.Stderr 65 66 if err := cmd.Run(); err != nil { 67 t.Fatalf("error running go install: %v", err) 68 } 69 70 cmd = exec.Command("ox") 71 bs, err := cmd.CombinedOutput() 72 if err != nil { 73 t.Fatalf("error running ox: %v", err) 74 } 75 76 exp := []byte("no command provided, please provide one") 77 if !bytes.Contains(bs, exp) { 78 t.Fatalf("%v does not contain expected output: %v", bs, exp) 79 } 80 }