Files
moby/daemon/containerfs_linux_test.go
Sebastiaan van Stijn ae0a3d6918 pkg/fileutils: move ReadSymlinkedDirectory internal to daemon
It has no external consumers, is written with specific behavior (including
some potentially surprising behavior), making it not a good candidate to
carry in the module.

This moves it internal to the daemon as a non-exported utility, so that
it's only accessible where it's currently used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-29 11:16:25 +02:00

40 lines
1.0 KiB
Go

package daemon
import (
"os"
"path/filepath"
"testing"
"gotest.tools/v3/assert"
)
func TestCreateIfNotExists(t *testing.T) {
t.Run("directory", func(t *testing.T) {
toCreate := filepath.Join(t.TempDir(), "tocreate")
err := createIfNotExists(toCreate, true)
assert.NilError(t, err)
fileinfo, err := os.Stat(toCreate)
assert.NilError(t, err, "Did not create destination")
assert.Assert(t, fileinfo.IsDir(), "Should have been a dir, seems it's not")
err = createIfNotExists(toCreate, true)
assert.NilError(t, err, "Should not fail if already exists")
})
t.Run("file", func(t *testing.T) {
toCreate := filepath.Join(t.TempDir(), "file/to/create")
err := createIfNotExists(toCreate, false)
assert.NilError(t, err)
fileinfo, err := os.Stat(toCreate)
assert.NilError(t, err, "Did not create destination")
assert.Assert(t, !fileinfo.IsDir(), "Should have been a file, but created a directory")
err = createIfNotExists(toCreate, true)
assert.NilError(t, err, "Should not fail if already exists")
})
}