Skip to content

Commit

Permalink
Fix TestDiffDirChangeWithOverlayfs
Browse files Browse the repository at this point in the history
The test was assuming TMPDIR to be on ext4, not on tmpfs.

Fix issue 247

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Oct 25, 2024
1 parent 50fa7de commit 9ef7291
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 34 deletions.
73 changes: 39 additions & 34 deletions fs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,50 +204,55 @@ func TestDiffDirChangeWithOverlayfs(t *testing.T) {
skipDiffTestOnNonLinux(t)
testutil.RequiresRoot(t)

l1 := fstest.Apply(
fstest.CreateDir("/dir1", 0700),
fstest.CreateFile("/dir1/f", []byte("/dir1/f"), 0644),
fstest.CreateDir("/dir1/d", 0700),
fstest.CreateFile("/dir1/d/f", []byte("/dir1/d/f"), 0644),
f := func() {
l1 := fstest.Apply(
fstest.CreateDir("/dir1", 0700),
fstest.CreateFile("/dir1/f", []byte("/dir1/f"), 0644),
fstest.CreateDir("/dir1/d", 0700),
fstest.CreateFile("/dir1/d/f", []byte("/dir1/d/f"), 0644),

fstest.CreateDir("/dir2", 0700),
fstest.CreateDir("/dir2/d", 0700),
fstest.CreateFile("/dir2/d/f", []byte("/dir2/d/f"), 0644),
fstest.CreateDir("/dir2", 0700),
fstest.CreateDir("/dir2/d", 0700),
fstest.CreateFile("/dir2/d/f", []byte("/dir2/d/f"), 0644),

fstest.CreateDir("/dir3", 0700),
fstest.CreateFile("/dir3/f", []byte("/dir3/f"), 0644),
)
fstest.CreateDir("/dir3", 0700),
fstest.CreateFile("/dir3/f", []byte("/dir3/f"), 0644),
)

l2 := fstest.Apply(
fstest.CreateDir("/dir1", 0700),
fstest.CreateFile("/dir1/f", []byte("/dir1/f-diff"), 0644),
fstest.CreateDeviceFile("/dir1/d", os.ModeDevice|os.ModeCharDevice, 0, 0),
l2 := fstest.Apply(
fstest.CreateDir("/dir1", 0700),
fstest.CreateFile("/dir1/f", []byte("/dir1/f-diff"), 0644),
fstest.CreateDeviceFile("/dir1/d", os.ModeDevice|os.ModeCharDevice, 0, 0),

fstest.CreateDir("/dir2", 0700),
fstest.CreateDir("/dir2/d", 0700),
fstest.CreateFile("/dir2/d/f", []byte("/dir2/d/f-diff"), 0644),
fstest.CreateDir("/dir2", 0700),
fstest.CreateDir("/dir2/d", 0700),
fstest.CreateFile("/dir2/d/f", []byte("/dir2/d/f-diff"), 0644),

fstest.CreateDir("/dir3", 0700),
// TODO(fuweid): check kernel version before apply
fstest.SetXAttr("/dir3", "user.overlay.opaque", "y"),
)
fstest.CreateDir("/dir3", 0700),
// TODO(fuweid): check kernel version before apply
fstest.SetXAttr("/dir3", "user.overlay.opaque", "y"),
)

diff := []TestChange{
Modify("/dir1"),
Modify("/dir1/f"),
Delete("/dir1/d"),
diff := []TestChange{
Modify("/dir1"),
Modify("/dir1/f"),
Delete("/dir1/d"),

Modify("/dir2"),
Modify("/dir2/d"),
Modify("/dir2/d/f"),
Modify("/dir2"),
Modify("/dir2/d"),
Modify("/dir2/d/f"),

Modify("/dir3"),
Delete("/dir3/.wh..opq"),
}
Modify("/dir3"),
Delete("/dir3/.wh..opq"),
}

if err := testDiffDirChange(l1, l2, DiffSourceOverlayFS, diff); err != nil {
t.Fatalf("failed diff dir change: %+v", err)
if err := testDiffDirChange(l1, l2, DiffSourceOverlayFS, diff); err != nil {
t.Fatalf("failed diff dir change: %+v", err)
}
}
// the test assumes ext4
// https://github.com/containerd/continuity/issues/247#issuecomment-2437014104
fstest.WithMkfs(t, f, "mkfs.ext4", "-F")
}

func TestParentDirectoryPermission(t *testing.T) {
Expand Down
44 changes: 44 additions & 0 deletions fs/fstest/mkfs_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fstest

import (
"os/exec"
"testing"

"github.com/containerd/continuity/testutil"
"github.com/containerd/continuity/testutil/loopback"
)

func WithMkfs(t *testing.T, f func(), mkfs ...string) {
testutil.RequiresRoot(t)
mnt := t.TempDir()
loop, err := loopback.New(100 << 20) // 100 MB
if err != nil {
t.Fatal(err)
}
defer loop.Close()
if out, err := exec.Command(mkfs[0], append(mkfs[1:], loop.Device)...).CombinedOutput(); err != nil {
t.Fatalf("could not mkfs (%v) %s: %v (out: %q)", mkfs, loop.Device, err, string(out))
}
if out, err := exec.Command("mount", loop.Device, mnt).CombinedOutput(); err != nil {
t.Fatalf("could not mount %s: %v (out: %q)", loop.Device, err, string(out))
}
defer testutil.Unmount(t, mnt)
t.Setenv("TMPDIR", mnt)
f()
}
25 changes: 25 additions & 0 deletions fs/fstest/mkfs_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build !linux

/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fstest

import "testing"

func WithMkfs(t *testing.T, f func(), mkfs ...string) {
t.Fatal("WithMkfs requires Linux")
}

0 comments on commit 9ef7291

Please sign in to comment.