From 17d7815bbd8a48b37e4770c1da2bbffaf69c4ed8 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 | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkg/fileutils/fileutils_test.go b/pkg/fileutils/fileutils_test.go index 9cc7b82b0..bcd65f1fd 100644 --- a/pkg/fileutils/fileutils_test.go +++ b/pkg/fileutils/fileutils_test.go @@ -181,6 +181,35 @@ func (s *FileUtilTestSuite) TestLink(c *check.C) { c.Assert(err, check.NotNil) } +func (s *FileUtilTestSuite) TestSymbolicLink(c *check.C) { + dirStr := filepath.Join(s.tmpDir, "TestSymLinkDir") + os.Mkdir(dirStr, 0755) + dirLinkStr := filepath.Join(s.tmpDir, "TestSymDirLinkName") + + 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 = Link(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 = Link(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")