-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
- Loading branch information
1 parent
c849603
commit cd6bcb3
Showing
7 changed files
with
98 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package fs | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func TestCopyDevicesAndFifo(t *testing.T) { | ||
requiresRoot(t) | ||
|
||
t1 := t.TempDir() | ||
|
||
err := mknod(filepath.Join(t1, "char"), unix.S_IFCHR|0444, int(unix.Mkdev(1, 9))) | ||
require.NoError(t, err) | ||
|
||
err = mknod(filepath.Join(t1, "block"), unix.S_IFBLK|0441, int(unix.Mkdev(3, 2))) | ||
require.NoError(t, err) | ||
|
||
err = mknod(filepath.Join(t1, "socket"), unix.S_IFSOCK|0555, 0) | ||
require.NoError(t, err) | ||
|
||
err = unix.Mkfifo(filepath.Join(t1, "fifo"), 0555) | ||
require.NoError(t, err) | ||
|
||
t2 := t.TempDir() | ||
|
||
err = Copy(context.TODO(), t1, ".", t2, ".") | ||
require.NoError(t, err) | ||
|
||
fi, err := os.Lstat(filepath.Join(t2, "char")) | ||
require.NoError(t, err) | ||
assert.Equal(t, os.ModeCharDevice, fi.Mode()&os.ModeCharDevice) | ||
assert.Equal(t, os.FileMode(0444), fi.Mode()&0777) | ||
|
||
fi, err = os.Lstat(filepath.Join(t2, "block")) | ||
require.NoError(t, err) | ||
assert.Equal(t, os.ModeDevice, fi.Mode()&os.ModeDevice) | ||
assert.Equal(t, os.FileMode(0441), fi.Mode()&0777) | ||
|
||
fi, err = os.Lstat(filepath.Join(t2, "fifo")) | ||
require.NoError(t, err) | ||
assert.Equal(t, os.ModeNamedPipe, fi.Mode()&os.ModeNamedPipe) | ||
assert.Equal(t, os.FileMode(0555), fi.Mode()&0777) | ||
|
||
fi, err = os.Lstat(filepath.Join(t2, "socket")) | ||
require.NoError(t, err) | ||
assert.NotEqual(t, os.ModeSocket, fi.Mode()&os.ModeSocket) // socket copied as stub | ||
assert.Equal(t, os.FileMode(0555), fi.Mode()&0777) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters