aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authorBartek Jaroszewski <jaroszewskibartek@gmail.com>2018-07-18 11:43:00 +0200
committerSantiago M. Mola <santi@mola.io>2018-10-30 11:43:00 +0100
commit507681b9a317a91c176460b6aaff1915ba4b9533 (patch)
treeca2f6f6d77dfa9366746f820b32bec2c30d16133 /repository_test.go
parentdfd6c820e3dc7477eaaf517d4ad3b34b62e6c42e (diff)
downloadgo-git-507681b9a317a91c176460b6aaff1915ba4b9533.tar.gz
repository: added cleanup for the PlainCloneContext()
Signed-off-by: Bartek Jaroszewski <jaroszewskibartek@gmail.com>
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go48
1 files changed, 43 insertions, 5 deletions
diff --git a/repository_test.go b/repository_test.go
index 07c3570..887901f 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -581,17 +581,55 @@ func (s *RepositorySuite) TestPlainCloneWithRemoteName(c *C) {
c.Assert(remote, NotNil)
}
-func (s *RepositorySuite) TestPlainCloneContext(c *C) {
+func (s *RepositorySuite) TestPlainCloneContextWithProperParameters(c *C) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
- _, err := PlainCloneContext(ctx, c.MkDir(), false, &CloneOptions{
+ r, err := PlainCloneContext(ctx, c.MkDir(), false, &CloneOptions{
URL: s.GetBasicLocalRepositoryURL(),
})
+ c.Assert(r, NotNil)
c.Assert(err, NotNil)
}
+func (s *RepositorySuite) TestPlainCloneContextWithIncorrectRepo(c *C) {
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ tmpDir := c.MkDir()
+ repoDir := filepath.Join(tmpDir, "repoDir")
+ r, err := PlainCloneContext(ctx, repoDir, false, &CloneOptions{
+ URL: "incorrectOnPurpose",
+ })
+ c.Assert(r, IsNil)
+ c.Assert(err, NotNil)
+
+ _, err = os.Stat(repoDir)
+ dirNotExist := os.IsNotExist(err)
+ c.Assert(dirNotExist, Equals, true)
+}
+
+func (s *RepositorySuite) TestPlainCloneContextWithNotEmptyDir(c *C) {
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ tmpDir := c.MkDir()
+ repoDirPath := filepath.Join(tmpDir, "repoDir")
+ err := os.Mkdir(repoDirPath, 0777)
+ c.Assert(err, IsNil)
+
+ dummyFile := filepath.Join(repoDirPath, "dummyFile")
+ err = ioutil.WriteFile(dummyFile, []byte(fmt.Sprint("dummyContent")), 0644)
+ c.Assert(err, IsNil)
+
+ r, err := PlainCloneContext(ctx, repoDirPath, false, &CloneOptions{
+ URL: "incorrectOnPurpose",
+ })
+ c.Assert(r, IsNil)
+ c.Assert(err, Equals, ErrDirNotEmpty)
+}
+
func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) {
if testing.Short() {
c.Skip("skipping test in short mode.")
@@ -2104,9 +2142,9 @@ func (s *RepositorySuite) TestResolveRevisionWithErrors(c *C) {
c.Assert(err, IsNil)
datas := map[string]string{
- "efs/heads/master~": "reference not found",
- "HEAD^3": `Revision invalid : "3" found must be 0, 1 or 2 after "^"`,
- "HEAD^{/whatever}": `No commit message match regexp : "whatever"`,
+ "efs/heads/master~": "reference not found",
+ "HEAD^3": `Revision invalid : "3" found must be 0, 1 or 2 after "^"`,
+ "HEAD^{/whatever}": `No commit message match regexp : "whatever"`,
"4e1243bd22c66e76c2ba9eddc1f91394e57f9f83": "reference not found",
"918c48b83bd081e863dbe1b80f8998f058cd8294": `refname "918c48b83bd081e863dbe1b80f8998f058cd8294" is ambiguous`,
}