github.com/halhenke/ghq@v0.8.1-0.20180207100234-7e68f823b46d/git_test.go (about) 1 package main 2 3 import ( 4 . "github.com/onsi/gomega" 5 "testing" 6 ) 7 8 func TestGitConfigAll(t *testing.T) { 9 RegisterTestingT(t) 10 11 Expect(GitConfigAll("ghq.non.existent.key")).To(HaveLen(0)) 12 } 13 14 func TestGitConfigURL(t *testing.T) { 15 RegisterTestingT(t) 16 17 if GitHasFeatureConfigURLMatch() == false { 18 t.Skip("Git does not have config --get-urlmatch feature") 19 } 20 21 reset, err := WithGitconfigFile(` 22 [ghq "https://ghe.example.com/"] 23 vcs = github 24 [ghq "https://ghe.example.com/hg/"] 25 vcs = hg 26 `) 27 if err != nil { 28 t.Fatal(err) 29 } 30 defer reset() 31 32 var ( 33 value string 34 ) 35 36 value, err = GitConfig("--get-urlmatch", "ghq.vcs", "https://ghe.example.com/foo/bar") 37 Expect(err).NotTo(HaveOccurred()) 38 Expect(value).To(Equal("github")) 39 40 value, err = GitConfig("--get-urlmatch", "ghq.vcs", "https://ghe.example.com/hg/repo") 41 Expect(err).NotTo(HaveOccurred()) 42 Expect(value).To(Equal("hg")) 43 44 value, err = GitConfig("--get-urlmatch", "ghq.vcs", "https://example.com") 45 Expect(err).NotTo(HaveOccurred()) 46 Expect(value).To(Equal("")) 47 } 48 49 func TestGitVersionOutputSatisfies(t *testing.T) { 50 RegisterTestingT(t) 51 52 Expect( 53 gitVersionOutputSatisfies( 54 "git version 1.7.9", 55 []uint{1, 8, 5}, 56 ), 57 ).To(BeFalse()) 58 59 Expect( 60 gitVersionOutputSatisfies( 61 "git version 1.8.2.3", 62 []uint{1, 8, 5}, 63 ), 64 ).To(BeFalse()) 65 66 Expect( 67 gitVersionOutputSatisfies( 68 "git version 1.8.5", 69 []uint{1, 8, 5}, 70 ), 71 ).To(BeTrue()) 72 73 Expect( 74 gitVersionOutputSatisfies( 75 "git version 1.9.1", 76 []uint{1, 8, 5}, 77 ), 78 ).To(BeTrue()) 79 80 Expect( 81 gitVersionOutputSatisfies( 82 "git version 2.0.0", 83 []uint{1, 8, 5}, 84 ), 85 ).To(BeTrue()) 86 }