Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more types of file to smoke #1229

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions smoke/tests/texture/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func MakeChunkDictLayer(t *testing.T, workDir string) *tool.Layer {
layer.CreateFile(t, "chunk-dict-file-3", []byte("dir-1/file-1"))
layer.CreateFile(t, "chunk-dict-file-4", []byte("dir-2/file-1"))
layer.CreateFile(t, "chunk-dict-file-5", []byte("dir-1/file-2"))
layer.CreateFile(t, "chunk-dict-file-6", []byte("This is poetry"))
layer.CreateFile(t, "chunk-dict-file-7", []byte("My name is long"))
layer.CreateLargeFile(t, "chunk-dict-file-8", 13)
layer.CreateHoledFile(t, "chunk-dict-file-9", []byte("hello world"), 1024, 1024*1024)
layer.CreateFile(t, "chunk-dict-file-10", []byte(""))

return layer
}
Expand Down Expand Up @@ -52,6 +57,24 @@ func MakeLowerLayer(t *testing.T, workDir string) *tool.Layer {
layer.CreateSpecialFile(t, "block-1", syscall.S_IFBLK)
layer.CreateSpecialFile(t, "fifo-1", syscall.S_IFIFO)

// Create file with chinese name
layer.CreateFile(t, "唐诗三百首", []byte("This is poetry"))

// Create file with long name
layer.CreateFile(t, "/test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.test-😉-name.", []byte("My name is long"))

// Create symlink with non-existed source file
layer.CreateSymlink(t, "dir-1/file-deleted-symlink", "dir-1/file-deleted")

// Create large file
layer.CreateLargeFile(t, "large-blob.bin", 13)

// Create holed file
layer.CreateHoledFile(t, "file-hole-1", []byte("hello world"), 1024, 1024*1024)

// Create empty file
layer.CreateFile(t, "empty.txt", []byte(""))

layer.CreateFile(t, "dir-1/file-2", []byte("dir-1/file-2"))
// Set file xattr (only `security.capability` xattr is supported in OCI layer)
tool.Run(t, fmt.Sprintf("setcap CAP_NET_RAW+ep %s", filepath.Join(workDir, "dir-1/file-2")))
Expand Down
6 changes: 3 additions & 3 deletions smoke/tests/tool/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ type File struct {

func GetXattrs(t *testing.T, path string) map[string]string {
xattrs := map[string]string{}
names, err := xattr.List(path)
names, err := xattr.LList(path)
require.NoError(t, err)
for _, name := range names {
data, err := xattr.Get(path, name)
data, err := xattr.LGet(path, name)
require.NoError(t, err)
xattrs[name] = string(data)
}
return xattrs
}

func NewFile(t *testing.T, path, target string) *File {
stat, err := os.Stat(path)
stat, err := os.Lstat(path)
require.NoError(t, err)

xattrs := GetXattrs(t, path)
Expand Down
27 changes: 27 additions & 0 deletions smoke/tests/tool/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ func (l *Layer) CreateFile(t *testing.T, name string, data []byte) {
require.NoError(t, err)
}

func (l *Layer) CreateLargeFile(t *testing.T, name string, sizeMB int) {
f, err := os.Create(filepath.Join(l.workDir, name))
require.NoError(t, err)
defer func() {
f.Close()
}()

for b := 1; b <= sizeMB; b++ {
_, err := f.Write(bytes.Repeat([]byte{byte(b)}, 1024*1024))
require.NoError(t, err)
}
}

func (l *Layer) CreateHoledFile(t *testing.T, name string, data []byte, offset, fileSize int64) {
f, err := os.Create(filepath.Join(l.workDir, name))
require.NoError(t, err)
defer func() {
f.Close()
}()

err = f.Truncate(fileSize)
require.NoError(t, err)

_, err = f.WriteAt(data, offset)
require.NoError(t, err)
}

func (l *Layer) CreateDir(t *testing.T, name string) {
err := os.MkdirAll(filepath.Join(l.workDir, name), 0755)
require.NoError(t, err)
Expand Down