From 50b2d0d31f0dfad8fe71d46f5ddbecffce18d5b7 Mon Sep 17 00:00:00 2001 From: Lu Fengqi Date: Fri, 14 Feb 2020 15:41:39 +0800 Subject: [PATCH] pkg/fileutils: add unit test for SymbolicLink Signed-off-by: Lu Fengqi --- pkg/fileutils/fileutils_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/fileutils/fileutils_test.go b/pkg/fileutils/fileutils_test.go index 9cc7b82b0..e075752d1 100644 --- a/pkg/fileutils/fileutils_test.go +++ b/pkg/fileutils/fileutils_test.go @@ -181,6 +181,39 @@ func (s *FileUtilTestSuite) TestLink(c *check.C) { c.Assert(err, check.NotNil) } +func (s *FileUtilTestSuite) TestSymbolicLink(c *check.C) { + nonExistPathStr := filepath.Join(s.tmpDir, "TestSymLinkFileNonExist") + linkStr := filepath.Join(s.tmpDir, "TestSymLinkNameFile") + err := SymbolicLink(nonExistPathStr, linkStr) + c.Assert(err, check.NotNil) + c.Assert(PathExist(linkStr), check.Equals, false) + + dirStr := filepath.Join(s.tmpDir, "TestSymLinkDir") + os.Mkdir(dirStr, 0755) + dirLinkStr := filepath.Join(s.tmpDir, "TestSymLinkNameDir") + err = SymbolicLink(dirStr, dirLinkStr) + c.Assert(err, check.IsNil) + c.Assert(PathExist(dirLinkStr), check.Equals, true) + + pathStr := filepath.Join(s.tmpDir, "TestSymLinkFile") + os.Create(pathStr) + linkStr = filepath.Join(s.tmpDir, "TestSymFileLinkName") + err = SymbolicLink(pathStr, linkStr) + c.Assert(err, check.IsNil) + c.Assert(PathExist(linkStr), check.Equals, true) + + linkStr = filepath.Join(s.tmpDir, "TestSymLinkNameExist") + os.Create(linkStr) + err = SymbolicLink(pathStr, linkStr) + c.Assert(err, check.IsNil) + c.Assert(PathExist(linkStr), check.Equals, true) + + linkStr = filepath.Join(s.tmpDir, "testSymLinkNonExistDir") + os.Mkdir(linkStr, 0755) + err = SymbolicLink(pathStr, linkStr) + c.Assert(err, check.NotNil) +} + func (s *FileUtilTestSuite) TestCopyFile(c *check.C) { srcPath := filepath.Join(s.tmpDir, "TestCopyFileSrc") dstPath := filepath.Join(s.tmpDir, "TestCopyFileDst")