github.com/LGUG2Z/story@v0.4.1/git/commit_test.go (about) 1 package git_test 2 3 import ( 4 "os" 5 6 "github.com/LGUG2Z/story/git" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 "github.com/spf13/afero" 10 ) 11 12 var _ = Describe("Commit", func() { 13 BeforeEach(func() { 14 if err := fs.MkdirAll("test", os.FileMode(0700)); err != nil { 15 Fail(err.Error()) 16 } 17 18 if err := os.Chdir("test"); err != nil { 19 Fail(err.Error()) 20 } 21 22 if err := initialiseRepository("."); err != nil { 23 Fail(err.Error()) 24 } 25 }) 26 27 AfterEach(func() { 28 if err := os.Chdir(".."); err != nil { 29 Fail(err.Error()) 30 } 31 32 if err := fs.RemoveAll("test"); err != nil { 33 Fail(err.Error()) 34 } 35 }) 36 37 Describe("Committing with staged files", func() { 38 It("Should commit the staged files", func() { 39 // Given a repository with files staged for commit 40 Expect(fs.MkdirAll("sub", os.FileMode(0700))).To(Succeed()) 41 Expect(afero.WriteFile(fs, "sub/newfile", []byte{}, os.FileMode(0666))).To(Succeed()) 42 _, err := git.Add(git.AddOpts{Project: "sub", Files: []string{"newfile"}}) 43 Expect(err).NotTo(HaveOccurred()) 44 45 // When I commit those files 46 output, err := git.Commit(git.CommitOpts{Project: "sub", Messages: []string{"Some msg"}}) 47 Expect(err).NotTo(HaveOccurred()) 48 49 // Then I see output confirming the commit 50 Expect(output).To(ContainSubstring("1 file changed")) 51 }) 52 }) 53 54 Describe("Committing with no staged files", func() { 55 It("Should return a message informing that there is nothing to commit", func() { 56 // Given a repository without files staged for commit 57 58 // When I try to commit 59 output, err := git.Commit(git.CommitOpts{Messages: []string{}}) 60 Expect(err).NotTo(HaveOccurred()) 61 62 // Then I see output confirming the commit 63 Expect(output).To(Equal("no staged changes to commit")) 64 }) 65 }) 66 })