From 3332e8d67dbe810d1607285d43fcd79470cf9961 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Tue, 30 Oct 2018 13:10:00 +0100 Subject: improve cleanup implementation, add more tests Signed-off-by: Santiago M. Mola --- repository_test.go | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'repository_test.go') 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) { -- cgit