github.com/LGUG2Z/story@v0.4.1/git/git_suite_test.go (about) 1 package git_test 2 3 import ( 4 "testing" 5 6 "fmt" 7 "os" 8 "os/exec" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 "github.com/spf13/afero" 13 ) 14 15 var fs afero.Fs 16 17 func TestGit(t *testing.T) { 18 RegisterFailHandler(Fail) 19 RunSpecs(t, "Git Suite") 20 } 21 22 var _ = Describe("Setup", func() { 23 BeforeSuite(func() { 24 fs = afero.NewOsFs() 25 }) 26 }) 27 28 func initialiseRepository(directory string) error { 29 command := exec.Command("git", "init") 30 command.Dir = directory 31 out, err := command.CombinedOutput() 32 if err != nil { 33 return fmt.Errorf("%s", out) 34 } 35 36 if err := afero.WriteFile(fs, fmt.Sprintf("%s/blank", directory), []byte{}, os.FileMode(0666)); err != nil { 37 return err 38 } 39 40 command = exec.Command("git", "add", ".") 41 command.Dir = directory 42 out, err = command.CombinedOutput() 43 if err != nil { 44 return fmt.Errorf("%s", out) 45 } 46 47 command = exec.Command("git", "commit", "-m", "initial") 48 command.Dir = directory 49 _, err = command.CombinedOutput() 50 if err != nil { 51 return fmt.Errorf("%s", out) 52 } 53 54 return nil 55 }