github.com/matthewdale/lab@v0.14.0/cmd/project_create_test.go (about) 1 package cmd 2 3 import ( 4 "os" 5 "os/exec" 6 "path" 7 "strings" 8 "testing" 9 10 "github.com/pkg/errors" 11 "github.com/stretchr/testify/require" 12 "github.com/zaquestion/lab/internal/git" 13 lab "github.com/zaquestion/lab/internal/gitlab" 14 ) 15 16 func Test_projectCreateCmd(t *testing.T) { 17 t.Parallel() 18 repo := copyTestRepo(t) 19 parts := strings.Split(repo, "/") 20 expectedPath := parts[len(parts)-1] 21 22 // remove the .git/config so no remotes exist 23 os.Remove(path.Join(repo, ".git/config")) 24 25 t.Run("create", func(t *testing.T) { 26 cmd := exec.Command("../lab_bin", "project", "create") 27 cmd.Dir = repo 28 29 b, err := cmd.CombinedOutput() 30 if err != nil { 31 t.Log(string(b)) 32 t.Fatal(err) 33 } 34 35 require.Contains(t, string(b), "https://gitlab.com/lab-testing/"+expectedPath+"\n") 36 37 gitCmd := git.New("remote", "get-url", "origin") 38 gitCmd.Dir = repo 39 gitCmd.Stdout = nil 40 gitCmd.Stderr = nil 41 remote, err := gitCmd.CombinedOutput() 42 if err != nil { 43 t.Fatal(err) 44 } 45 require.Equal(t, "git@gitlab.com:lab-testing/"+expectedPath+".git\n", string(remote)) 46 }) 47 48 p, err := lab.FindProject(expectedPath) 49 if err != nil { 50 t.Fatal(errors.Wrap(err, "failed to find project for cleanup")) 51 } 52 err = lab.ProjectDelete(p.ID) 53 if err != nil { 54 t.Fatal(errors.Wrap(err, "failed to delete project during cleanup")) 55 } 56 } 57 58 func Test_determinePath(t *testing.T) { 59 t.Parallel() 60 tests := []struct { 61 desc string 62 args []string 63 expected string 64 }{ 65 {"arguemnt", []string{"new_project"}, "new_project"}, 66 // All cmd package tests run in the lab/testdata directory 67 {"git working dir", []string{}, "testdata"}, 68 } 69 70 for _, test := range tests { 71 test := test 72 t.Run(test.desc, func(t *testing.T) { 73 t.Parallel() 74 require.Equal(t, test.expected, determinePath(test.args, "")) 75 }) 76 } 77 }