github.com/gfleury/gobbs@v0.0.0-20200831213239-44ca2b94c1a1/common/git_test.go (about) 1 package common 2 3 import ( 4 "os" 5 "testing" 6 7 "gopkg.in/check.v1" 8 ) 9 10 func Test(t *testing.T) { check.TestingT(t) } 11 12 type S struct { 13 } 14 15 var _ = check.Suite(&S{}) 16 17 func (s *S) TestGitInfo(c *check.C) { 18 err := os.Chdir("..") 19 c.Assert(err, check.IsNil) 20 host, project, repo, err := GitInfo() 21 c.Assert(err, check.IsNil) 22 c.Assert(host, check.Equals, "github.com") 23 c.Assert(project, check.Equals, "gfleury") 24 c.Assert(repo, check.Equals, "gobbs") 25 err = os.Chdir("common") 26 c.Assert(err, check.IsNil) 27 } 28 29 func (s *S) TestGitInfoErr(c *check.C) { 30 _, _, _, err := GitInfo() 31 c.Assert(err, check.NotNil) 32 } 33 34 func (s *S) TestparseGitURL(c *check.C) { 35 host, project, repo, err := parseGitURL("https://github.com/gfleury/gobbs.git") 36 c.Assert(err, check.IsNil) 37 c.Assert(host, check.Equals, "github.com") 38 c.Assert(project, check.Equals, "gfleury") 39 c.Assert(repo, check.Equals, "gobbs") 40 } 41 42 func (s *S) TestparseGitURLSSHURL(c *check.C) { 43 host, project, repo, err := parseGitURL("ssh://git@stash.example.com:7999/project/repo01.git") 44 c.Assert(err, check.IsNil) 45 c.Assert(host, check.Equals, "stash.example.com") 46 c.Assert(project, check.Equals, "project") 47 c.Assert(repo, check.Equals, "repo01") 48 } 49 50 func (s *S) TestparseGitURLSCPSSHURL(c *check.C) { 51 host, project, repo, err := parseGitURL("git@github.com:gfleury/gobbs.git") 52 c.Assert(err, check.IsNil) 53 c.Assert(host, check.Equals, "github.com") 54 c.Assert(project, check.Equals, "gfleury") 55 c.Assert(repo, check.Equals, "gobbs") 56 } 57 58 func (s *S) TestparseGitURLSCPSSHURL_2(c *check.C) { 59 host, project, repo, err := parseGitURL("git@github.com:/gfleury/gobbs.git") 60 c.Assert(err, check.IsNil) 61 c.Assert(host, check.Equals, "github.com") 62 c.Assert(project, check.Equals, "gfleury") 63 c.Assert(repo, check.Equals, "gobbs") 64 }