diff options
Diffstat (limited to 'container/path_test.go')
| -rw-r--r-- | container/path_test.go | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/container/path_test.go b/container/path_test.go index 3b2869e5..c3b68b3d 100644 --- a/container/path_test.go +++ b/container/path_test.go @@ -2,7 +2,6 @@ package container import ( "errors" - "fmt" "io" "math" "os" @@ -56,20 +55,27 @@ func InternalToHostOvlEscape(s string) string { return EscapeOverlayDataSegment( func TestCreateFile(t *testing.T) { t.Run("nonexistent", func(t *testing.T) { - if err := createFile(path.Join(Nonexistent, ":3"), 0644, 0755, nil); !errors.Is(err, wrapErrSelf(&os.PathError{ - Op: "mkdir", - Path: "/proc/nonexistent", - Err: syscall.ENOENT, - })) { - t.Errorf("createFile: error = %v", err) - } - if err := createFile(path.Join(Nonexistent), 0644, 0755, nil); !errors.Is(err, wrapErrSelf(&os.PathError{ - Op: "open", - Path: "/proc/nonexistent", - Err: syscall.ENOENT, - })) { - t.Errorf("createFile: error = %v", err) - } + t.Run("mkdir", func(t *testing.T) { + wantErr := &os.PathError{ + Op: "mkdir", + Path: "/proc/nonexistent", + Err: syscall.ENOENT, + } + if err := createFile(path.Join(Nonexistent, ":3"), 0644, 0755, nil); !reflect.DeepEqual(err, wantErr) { + t.Errorf("createFile: error = %#v, want %#v", err, wantErr) + } + }) + + t.Run("open", func(t *testing.T) { + wantErr := &os.PathError{ + Op: "open", + Path: "/proc/nonexistent", + Err: syscall.ENOENT, + } + if err := createFile(path.Join(Nonexistent), 0644, 0755, nil); !reflect.DeepEqual(err, wantErr) { + t.Errorf("createFile: error = %#v, want %#v", err, wantErr) + } + }) }) t.Run("touch", func(t *testing.T) { @@ -120,13 +126,13 @@ func TestEnsureFile(t *testing.T) { t.Fatalf("Chmod: error = %v", err) } - wantErr := wrapErrSelf(&os.PathError{ + wantErr := &os.PathError{ Op: "stat", Path: pathname, Err: syscall.EACCES, - }) - if err := ensureFile(pathname, 0644, 0755); !errors.Is(err, wantErr) { - t.Errorf("ensureFile: error = %v, want %v", err, wantErr) + } + if err := ensureFile(pathname, 0644, 0755); !reflect.DeepEqual(err, wantErr) { + t.Errorf("ensureFile: error = %#v, want %#v", err, wantErr) } if err := os.Chmod(tempDir, 0755); err != nil { @@ -136,9 +142,9 @@ func TestEnsureFile(t *testing.T) { t.Run("directory", func(t *testing.T) { pathname := t.TempDir() - wantErr := msg.WrapErr(syscall.EISDIR, fmt.Sprintf("path %q is a directory", pathname)) - if err := ensureFile(pathname, 0644, 0755); !errors.Is(err, wantErr) { - t.Errorf("ensureFile: error = %v, want %v", err, wantErr) + wantErr := &os.PathError{Op: "ensure", Path: pathname, Err: syscall.EISDIR} + if err := ensureFile(pathname, 0644, 0755); !reflect.DeepEqual(err, wantErr) { + t.Errorf("ensureFile: error = %#v, want %#v", err, wantErr) } }) @@ -177,12 +183,12 @@ func TestProcPaths(t *testing.T) { t.Run("mountinfo", func(t *testing.T) { t.Run("nonexistent", func(t *testing.T) { nonexistentProc := newProcPaths(direct{}, t.TempDir()) - wantErr := wrapErrSelf(&os.PathError{ + wantErr := &os.PathError{ Op: "open", Path: nonexistentProc.self + "/mountinfo", Err: syscall.ENOENT, - }) - if err := nonexistentProc.mountinfo(func(*vfs.MountInfoDecoder) error { return syscall.EINVAL }); !errors.Is(err, wantErr) { + } + if err := nonexistentProc.mountinfo(func(*vfs.MountInfoDecoder) error { return syscall.EINVAL }); !reflect.DeepEqual(err, wantErr) { t.Errorf("mountinfo: error = %v, want %v", err, wantErr) } }) @@ -217,11 +223,11 @@ func TestProcPaths(t *testing.T) { t.Run("closed", func(t *testing.T) { p := newProcPaths(direct{}, tempDir) - wantErr := wrapErrSelf(&os.PathError{ + wantErr := &os.PathError{ Op: "close", Path: p.self + "/mountinfo", Err: os.ErrClosed, - }) + } if err := p.mountinfo(func(d *vfs.MountInfoDecoder) error { v := reflect.ValueOf(d).Elem().FieldByName("s").Elem().FieldByName("r") v = reflect.NewAt(v.Type(), unsafe.Pointer(v.UnsafeAddr())) @@ -231,8 +237,8 @@ func TestProcPaths(t *testing.T) { } else { return f.Close() } - }); !errors.Is(err, wantErr) { - t.Errorf("mountinfo: error = %v, want %v", err, wantErr) + }); !reflect.DeepEqual(err, wantErr) { + t.Errorf("mountinfo: error = %#v, want %#v", err, wantErr) } }) |
