github.com/lgug2z/story@v0.4.1/git/clone_test.go (about) 1 package git_test 2 3 import ( 4 "os" 5 "os/exec" 6 7 "github.com/LGUG2Z/story/git" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 "github.com/spf13/afero" 11 ) 12 13 var _ = Describe("Clone", func() { 14 BeforeEach(func() { 15 if err := fs.MkdirAll("test", os.FileMode(0700)); err != nil { 16 Fail(err.Error()) 17 } 18 19 if err := os.Chdir("test"); err != nil { 20 Fail(err.Error()) 21 } 22 23 if err := initialiseRepository("."); err != nil { 24 Fail(err.Error()) 25 } 26 }) 27 28 AfterEach(func() { 29 if err := os.Chdir(".."); err != nil { 30 Fail(err.Error()) 31 } 32 33 if err := fs.RemoveAll("test"); err != nil { 34 Fail(err.Error()) 35 } 36 }) 37 38 Describe("Cloning repositories", func() { 39 It("Should clone a repository into a given folder", func() { 40 // Given a remote / bare repository 41 Expect(fs.MkdirAll("remote", os.FileMode(0700))).To(Succeed()) 42 command := exec.Command("git", "init", "--bare") 43 command.Dir = "remote" 44 _, err := command.CombinedOutput() 45 Expect(err).NotTo(HaveOccurred()) 46 47 // When I clone that remote repository 48 _, err = git.Clone(git.CloneOpts{Repository: "remote", Directory: "cloned"}) 49 Expect(err).NotTo(HaveOccurred()) 50 51 // Then the cloned directory should exist on the fs 52 clonedExists, err := afero.DirExists(fs, "cloned") 53 Expect(err).NotTo(HaveOccurred()) 54 clonedDotGitExists, err := afero.DirExists(fs, "cloned/.git") 55 Expect(err).NotTo(HaveOccurred()) 56 57 Expect(clonedExists).To(BeTrue()) 58 Expect(clonedDotGitExists).To(BeTrue()) 59 }) 60 }) 61 })