Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
pkg/fileutils: add unit test for SymbolicLink
Browse files Browse the repository at this point in the history
Signed-off-by: Lu Fengqi <[email protected]>
  • Loading branch information
Lu Fengqi committed Feb 17, 2020
1 parent 16763d6 commit 082e612
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/fileutils/fileutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,38 @@ func (s *FileUtilTestSuite) TestLink(c *check.C) {
c.Assert(err, check.NotNil)
}

func (s *FileUtilTestSuite) TestSymbolicLink(c *check.C) {
pathStr := filepath.Join(s.tmpDir, "TestSymLinkFileNonExist")
linkStr := filepath.Join(s.tmpDir, "TestSymLinkNameFileNonExist")
err := SymbolicLink(pathStr, linkStr)
c.Assert(err, check.NotNil)
c.Assert(PathExist(linkStr), check.Equals, false)

pathStr = filepath.Join(s.tmpDir, "TestSymLinkDir")
os.Mkdir(pathStr, 0755)
linkStr = filepath.Join(s.tmpDir, "TestSymLinkNameDir")
err = SymbolicLink(pathStr, linkStr)
c.Assert(err, check.IsNil)
c.Assert(PathExist(linkStr), check.Equals, true)

pathStr = filepath.Join(s.tmpDir, "TestSymLinkFile")
os.Create(pathStr)
linkStr = filepath.Join(s.tmpDir, "TestSymLinkNameFile")
err = SymbolicLink(pathStr, linkStr)
c.Assert(err, check.IsNil)
c.Assert(PathExist(linkStr), check.Equals, true)

linkStr = filepath.Join(s.tmpDir, "TestSymLinkNameDirExist")
os.Mkdir(linkStr, 0755)
err = SymbolicLink(pathStr, linkStr)
c.Assert(err, check.NotNil)

linkStr = filepath.Join(s.tmpDir, "TestSymLinkNameFileExist")
os.Create(linkStr)
err = SymbolicLink(pathStr, linkStr)
c.Assert(err, check.IsNil)
}

func (s *FileUtilTestSuite) TestCopyFile(c *check.C) {
srcPath := filepath.Join(s.tmpDir, "TestCopyFileSrc")
dstPath := filepath.Join(s.tmpDir, "TestCopyFileDst")
Expand Down

0 comments on commit 082e612

Please sign in to comment.