aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2018-10-30 13:10:00 +0100
committerSantiago M. Mola <santi@mola.io>2018-10-30 13:10:00 +0100
commit3332e8d67dbe810d1607285d43fcd79470cf9961 (patch)
treed737ffe63ecd0059439517ee66a4168c0565807d /repository_test.go
parent507681b9a317a91c176460b6aaff1915ba4b9533 (diff)
downloadgo-git-3332e8d67dbe810d1607285d43fcd79470cf9961.tar.gz
improve cleanup implementation, add more tests
Signed-off-by: Santiago M. Mola <santi@mola.io>
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go54
1 files changed, 48 insertions, 6 deletions
diff --git a/repository_test.go b/repository_test.go
index 887901f..ba2cf1a 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -593,24 +593,66 @@ func (s *RepositorySuite) TestPlainCloneContextWithProperParameters(c *C) {
c.Assert(err, NotNil)
}
-func (s *RepositorySuite) TestPlainCloneContextWithIncorrectRepo(c *C) {
+func (s *RepositorySuite) TestPlainCloneContextNonExistentWithExistentDir(c *C) {
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ tmpDir := c.MkDir()
+ repoDir := tmpDir
+
+ r, err := PlainCloneContext(ctx, repoDir, false, &CloneOptions{
+ URL: "incorrectOnPurpose",
+ })
+ c.Assert(r, NotNil)
+ c.Assert(err, NotNil)
+
+ _, err = os.Stat(repoDir)
+ c.Assert(os.IsNotExist(err), Equals, false)
+
+ names, err := ioutil.ReadDir(repoDir)
+ c.Assert(err, IsNil)
+ c.Assert(names, HasLen, 0)
+}
+
+func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNonExistentDir(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(r, NotNil)
c.Assert(err, NotNil)
_, err = os.Stat(repoDir)
- dirNotExist := os.IsNotExist(err)
- c.Assert(dirNotExist, Equals, true)
+ c.Assert(os.IsNotExist(err), Equals, true)
+}
+
+func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNotDir(c *C) {
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ tmpDir := c.MkDir()
+ repoDir := filepath.Join(tmpDir, "repoDir")
+ f, err := os.Create(repoDir)
+ c.Assert(err, IsNil)
+ c.Assert(f.Close(), IsNil)
+
+ r, err := PlainCloneContext(ctx, repoDir, false, &CloneOptions{
+ URL: "incorrectOnPurpose",
+ })
+ c.Assert(r, IsNil)
+ c.Assert(err, NotNil)
+
+ fi, err := os.Stat(repoDir)
+ c.Assert(err, IsNil)
+ c.Assert(fi.IsDir(), Equals, false)
}
-func (s *RepositorySuite) TestPlainCloneContextWithNotEmptyDir(c *C) {
+func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNotEmptyDir(c *C) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
@@ -627,7 +669,7 @@ func (s *RepositorySuite) TestPlainCloneContextWithNotEmptyDir(c *C) {
URL: "incorrectOnPurpose",
})
c.Assert(r, IsNil)
- c.Assert(err, Equals, ErrDirNotEmpty)
+ c.Assert(err, NotNil)
}
func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) {