Skip to content

Commit

Permalink
test: improve osutil.mkdir test coverage (#492)
Browse files Browse the repository at this point in the history
Added two more test cases to improve test coverage.

If the path already exists but it's not a directory, a `syscall.ENOTDIR`
error is expected.
  • Loading branch information
IronCore864 authored Aug 26, 2024
1 parent 9c9e95a commit 5c8a9ab
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions internals/osutil/mkdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ func (mkdirSuite) TestExistNotOK(c *check.C) {
c.Assert(err, check.ErrorMatches, `.*: file exists`)
}

func (mkdirSuite) TestExistsButNotDir(c *check.C) {
tmpDir := c.MkDir()

_, err := os.Create(tmpDir + "/foo")
c.Assert(err, check.IsNil)

err = osutil.Mkdir(tmpDir+"/foo", 0o755, nil)
c.Assert(err, check.ErrorMatches, `.*: not a directory`)
}

func (mkdirSuite) TestDirEndWithSlash(c *check.C) {
tmpDir := c.MkDir()

Expand Down Expand Up @@ -112,6 +122,18 @@ func (mkdirSuite) TestMakeParentsAndExistNotOK(c *check.C) {
c.Assert(err, check.ErrorMatches, `.*: file exists`)
}

func (mkdirSuite) TestParentExistsButNotDir(c *check.C) {
tmpDir := c.MkDir()

_, err := os.Create(tmpDir + "/foo")
c.Assert(err, check.IsNil)

err = osutil.Mkdir(tmpDir+"/foo/bar/", 0o755, &osutil.MkdirOptions{
MakeParents: true,
})
c.Assert(err, check.ErrorMatches, `.*: not a directory`)
}

func (mkdirSuite) TestChmod(c *check.C) {
oldmask := syscall.Umask(0022)
defer syscall.Umask(oldmask)
Expand Down

0 comments on commit 5c8a9ab

Please sign in to comment.