github.com/LGUG2Z/story@v0.4.1/cli/cli_suite_test.go (about) 1 package cli_test 2 3 import ( 4 "testing" 5 6 "encoding/json" 7 "fmt" 8 "os" 9 "os/exec" 10 11 "github.com/LGUG2Z/story/git" 12 "github.com/LGUG2Z/story/manifest" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 "github.com/spf13/afero" 16 ) 17 18 var fs afero.Fs 19 20 func TestCli(t *testing.T) { 21 RegisterFailHandler(Fail) 22 RunSpecs(t, "Cli Suite") 23 } 24 25 var _ = Describe("Setup", func() { 26 BeforeSuite(func() { 27 fs = afero.NewOsFs() 28 }) 29 }) 30 31 func initialiseMetarepo(directory string) error { 32 command := exec.Command("git", "init") 33 command.Dir = directory 34 out, err := command.CombinedOutput() 35 if err != nil { 36 return fmt.Errorf("%s", out) 37 } 38 39 m := manifest.Meta{ 40 Organisation: "test-org", 41 Artifacts: map[string]bool{"one": false}, 42 Projects: map[string]string{"one": "git@github.com:test-org/one.git", "two": "external/remote"}, 43 } 44 45 b, err := json.MarshalIndent(m, "", " ") 46 if err != nil { 47 return err 48 } 49 50 if err := afero.WriteFile(fs, fmt.Sprintf("%s/.meta", directory), b, os.FileMode(0666)); err != nil { 51 return err 52 } 53 54 _, err = git.Add(git.AddOpts{Files: []string{".meta"}}) 55 if err != nil { 56 return err 57 } 58 59 command = exec.Command("git", "commit", "-m", "Initialise metarepo") 60 command.Dir = directory 61 _, err = command.CombinedOutput() 62 if err != nil { 63 return fmt.Errorf("%s", out) 64 } 65 66 return nil 67 }