github.com/hideaki10/command-line@v0.9.8/bk/no-test/repo_manager_test.go (about) 1 // package repo_manager 2 3 // import ( 4 // "os" 5 // "path" 6 // "strings" 7 8 // . "github.com/hideaki10/command-line/pkg/helpers" 9 // . "github.com/onsi/ginkgo" 10 // . "github.com/onsi/gomega" 11 // ) 12 13 // const baseDir = "tmp/test-multi-git" 14 15 // var repoList = []string{} 16 17 // var _ = Describe("Repo manager tests", func() { 18 // var err error 19 20 // removeAll := func() { 21 // err = os.RemoveAll(baseDir) 22 // Ω(err).Should(BeNil()) 23 // } 24 25 // BeforeEach(func() { 26 // removeAll() 27 // err = CreateDir(baseDir, "dir-1", true) 28 // Ω(err).Should(BeNil()) 29 // repoList = []string{"dir-1"} 30 // }) 31 // AfterEach(removeAll) 32 33 // Context("Tests for failure cases", func() { 34 // It("Should fail with invalid base dir", func() { 35 // _, err := NewRepoManager("/no-such-dir", repoList, true) 36 // Ω(err).ShouldNot(BeNil()) 37 // }) 38 39 // It("Should fail with empty repo list", func() { 40 // _, err := NewRepoManager(baseDir, []string{}, true) 41 // Ω(err).ShouldNot(BeNil()) 42 // }) 43 // }) 44 45 // Context("Tests for success cases", func() { 46 // It("Should get repo list successfully", func() { 47 // rm, err := NewRepoManager(baseDir, repoList, true) 48 // Ω(err).Should(BeNil()) 49 50 // repos := rm.GetRepos() 51 // Ω(repos).Should(HaveLen(1)) 52 // actual := path.Join(baseDir, repoList[0]) 53 // expected := repos[0] 54 // Ω(actual).Should(Equal(expected)) 55 // }) 56 57 // It("Should get repo list successfully with non-git directories", func() { 58 // repoList = append(repoList, "dir-2") 59 // CreateDir(baseDir, repoList[1], true) 60 // CreateDir(baseDir, "not-a-git-repo", false) 61 // rm, err := NewRepoManager(baseDir, repoList, true) 62 // Ω(err).Should(BeNil()) 63 64 // repos := rm.GetRepos() 65 // Ω(repos).Should(HaveLen(2)) 66 // Ω(repos[0] == path.Join(baseDir, repoList[0])).Should(BeTrue()) 67 // Ω(repos[1] == path.Join(baseDir, repoList[1])).Should(BeTrue()) 68 // }) 69 70 // It("Should get repo list successfully with non-git directories", func() { 71 // repoList = append(repoList, "dir-2") 72 // CreateDir(baseDir, repoList[1], true) 73 // CreateDir(baseDir, "not-a-git-repo", false) 74 // rm, err := NewRepoManager(baseDir, repoList, true) 75 // Ω(err).Should(BeNil()) 76 77 // repos := rm.GetRepos() 78 // Ω(repos).Should(HaveLen(2)) 79 // Ω(repos[0] == path.Join(baseDir, repoList[0])).Should(BeTrue()) 80 // Ω(repos[1] == path.Join(baseDir, repoList[1])).Should(BeTrue()) 81 // }) 82 83 // It("Should create branches successfully", func() { 84 // repoList = append(repoList, "dir-2") 85 // CreateDir(baseDir, repoList[1], true) 86 // rm, err := NewRepoManager(baseDir, repoList, true) 87 // Ω(err).Should(BeNil()) 88 89 // output, err := rm.Exec("checkout -b test-branch") 90 // Ω(err).Should(BeNil()) 91 92 // for _, out := range output { 93 // Ω(out).Should(Equal("Switched to a new branch 'test-branch'\n")) 94 // } 95 // }) 96 97 // It("Should commit files successfully", func() { 98 // rm, err := NewRepoManager(baseDir, repoList, true) 99 // Ω(err).Should(BeNil()) 100 101 // output, err := rm.Exec("checkout -b test-branch") 102 // Ω(err).Should(BeNil()) 103 104 // for _, out := range output { 105 // Ω(out).Should(Equal("Switched to a new branch 'test-branch'\n")) 106 // } 107 108 // err = AddFiles(baseDir, repoList[0], true, "file_1.txt", "file_2.txt") 109 // Ω(err).Should(BeNil()) 110 111 // // Restore working directory after executing the command 112 // wd, _ := os.Getwd() 113 // defer os.Chdir(wd) 114 115 // dir := path.Join(baseDir, repoList[0]) 116 // err = os.Chdir(dir) 117 // Ω(err).Should(BeNil()) 118 119 // output, err = rm.Exec("log --oneline") 120 // Ω(err).Should(BeNil()) 121 122 // ok := strings.HasSuffix(output[dir], "added some files...\n") 123 // Ω(ok).Should(BeTrue()) 124 // }) 125 // }) 126 // }) 127 //