Skip to content

Commit

Permalink
Adding testing of two devices in a directory
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Peixoto Ferreira <alexandref75@gmail.com>
(cherry picked from commit 838afd2)
  • Loading branch information
alexandref75 committed Sep 7, 2021
1 parent 0ca2e27 commit c7ed09d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions oci/spec_opts_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,37 @@ func TestGetDevices(t *testing.T) {
}
})
})
t.Run("two devices", func(t *testing.T) {
nullDev := filepath.Join(dir, "null")
if err := ioutil.WriteFile(nullDev, nil, 0600); err != nil {
t.Fatal(err)
}

if err := unix.Mount("/dev/null", nullDev, "", unix.MS_BIND, ""); err != nil {
t.Fatal(err)
}
defer unix.Unmount(filepath.Join(dir, "null"), unix.MNT_DETACH)
devices, err := getDevices(dir, "")
if err != nil {
t.Fatal(err)
}

if len(devices) != 2 {
t.Fatalf("expected two devices %v", devices)
}
if devices[0].Path == devices[1].Path {
t.Fatalf("got same path for the two devices %s", devices[0].Path)
}
if devices[0].Path != zero && devices[0].Path != nullDev {
t.Fatalf("got unexpected device path %s", devices[0].Path)
}
if devices[1].Path != zero && devices[1].Path != nullDev {
t.Fatalf("got unexpected device path %s", devices[1].Path)
}
if devices[0].Major == devices[1].Major && devices[0].Minor == devices[1].Minor {
t.Fatalf("got sema mojor and minor on two devices %s %s", devices[0].Path, devices[1].Path)
}
})
t.Run("With symlink in dir", func(t *testing.T) {
if err := os.Symlink("/dev/zero", filepath.Join(dir, "zerosym")); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit c7ed09d

Please sign in to comment.