diff options
| author | Eric Biggers <ebiggers@google.com> | 2022-01-26 23:29:51 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-26 23:29:51 -0800 |
| commit | be16498681558ab9379af792df52e753457cf18a (patch) | |
| tree | a323c2a033216353b96b19e3db36b19071fcfb97 /filesystem/mountpoint_test.go | |
| parent | 8f619f9478ef5d3d616908bd2b30cb85d8034020 (diff) | |
| parent | c2fb96c60d7678110bca14ff0a213243bd97cb08 (diff) | |
Merge pull request #340 from google/fix-btrfs
Allow the root directory to be a btrfs filesystem
Diffstat (limited to 'filesystem/mountpoint_test.go')
| -rw-r--r-- | filesystem/mountpoint_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/filesystem/mountpoint_test.go b/filesystem/mountpoint_test.go index 6600d87..749e5e3 100644 --- a/filesystem/mountpoint_test.go +++ b/filesystem/mountpoint_test.go @@ -90,6 +90,12 @@ func TestLoadMountInfoBasic(t *testing.T) { if mnt.ReadOnly { t.Error("Wrong readonly flag") } + if len(mountsByPath) != 1 { + t.Error("mountsByPath doesn't contain exactly one entry") + } + if mountsByPath[mnt.Path] != mnt { + t.Error("mountsByPath doesn't contain the correct entry") + } } // Test that Mount.Device is set to the mountpoint's source device if @@ -405,6 +411,40 @@ func TestGetMountFromLink(t *testing.T) { } } +// Test that makeLink() is including the expected information in links. +func TestMakeLink(t *testing.T) { + mnt, err := getTestMount(t) + if err != nil { + t.Skip(err) + } + link, err := makeLink(mnt) + if err != nil { + t.Fatal(err) + } + + // Normally, both UUID and PATH should be included. + if !strings.Contains(link, "UUID=") { + t.Fatal("Link doesn't contain UUID") + } + if !strings.Contains(link, "PATH=") { + t.Fatal("Link doesn't contain PATH") + } + + // Without a valid device number, only PATH should be included. + mntCopy := *mnt + mntCopy.DeviceNumber = 0 + link, err = makeLink(&mntCopy) + if err != nil { + t.Fatal(err) + } + if strings.Contains(link, "UUID=") { + t.Fatal("Link shouldn't contain UUID") + } + if !strings.Contains(link, "PATH=") { + t.Fatal("Link doesn't contain PATH") + } +} + // Test that old filesystem links that contain a UUID only still work. func TestGetMountFromLegacyLink(t *testing.T) { mnt, err := getTestMount(t) @@ -450,6 +490,16 @@ func TestGetMountFromLinkFallback(t *testing.T) { t.Fatal("Link doesn't point to the same Mount") } + // only PATH given at all (should succeed) + link = fmt.Sprintf("PATH=%s\n", mnt.Path) + linkedMnt, err = getMountFromLink(link) + if err != nil { + t.Fatal(err) + } + if linkedMnt != mnt { + t.Fatal("Link doesn't point to the same Mount") + } + // only UUID valid (should succeed) link = fmt.Sprintf("UUID=%s\nPATH=%s\n", goodUUID, badPath) if linkedMnt, err = getMountFromLink(link); err != nil { |