File: shared_test.go

package info (click to toggle)
snapd 2.73-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 81,460 kB
  • sloc: sh: 16,736; ansic: 16,652; python: 11,215; makefile: 1,966; exp: 190; awk: 58; xml: 22
file content (76 lines) | stat: -rw-r--r-- 2,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package vfs_test

import (
	"io/fs"
	"testing"
	"testing/fstest"

	"github.com/snapcore/snapd/osutil/vfs"
)

func TestVFS_MakeShared(t *testing.T) {
	t.Run("success", func(t *testing.T) {
		v := vfs.NewVFS(fstest.MapFS{"home": &fstest.MapFile{Mode: fs.ModeDir}})
		assertSuccess(t, v.MakeShared(""))
		assertSuccess(t, v.Mount(fstest.MapFS{}, "home"))
		assertVFS(t, v, `
-1 -1 0:0 / / rw shared:1 - (fstype) (source) rw
0  -1 0:0 / /home rw shared:2 - (fstype) (source) rw
`)
	})

	t.Run("twice", func(t *testing.T) {
		v := vfs.NewVFS(fstest.MapFS{})
		assertSuccess(t, v.MakeShared(""))
		assertSuccess(t, v.MakeShared(""))
		assertVFS(t, v, `
-1 -1 0:0 / / rw shared:1 - (fstype) (source) rw
`)
	})

	t.Run("not-mount-point", func(t *testing.T) {
		v := vfs.NewVFS(fstest.MapFS{"home": &fstest.MapFile{Mode: fs.ModeDir}})
		assertErrorIs(t, v.MakeShared("home"), vfs.ErrNotMounted)
		assertVFS(t, v, `
-1 -1 0:0 / / rw - (fstype) (source) rw
`)
	})
}

func TestVFS_RecursivelyMakeShared(t *testing.T) {
	t.Run("top-level", func(t *testing.T) {
		v := vfs.NewVFS(fstest.MapFS{"home": &fstest.MapFile{Mode: fs.ModeDir}})
		assertSuccess(t, v.Mount(fstest.MapFS{"zyga": &fstest.MapFile{Mode: fs.ModeDir}}, "home"))
		assertSuccess(t, v.Mount(fstest.MapFS{}, "home/zyga"))
		assertSuccess(t, v.MakeRecursivelyShared(""))
		assertVFS(t, v, `
-1 -1 0:0 / / rw shared:1 - (fstype) (source) rw
0  -1 0:0 / /home rw shared:2 - (fstype) (source) rw
1  0 0:0 / /home/zyga rw shared:3 - (fstype) (source) rw
`)
	})

	t.Run("not-top-level", func(t *testing.T) {
		v := vfs.NewVFS(fstest.MapFS{"home": &fstest.MapFile{Mode: fs.ModeDir}})
		assertSuccess(t, v.Mount(fstest.MapFS{"zyga": &fstest.MapFile{Mode: fs.ModeDir}}, "home"))
		assertSuccess(t, v.Mount(fstest.MapFS{}, "home/zyga"))
		assertSuccess(t, v.MakeRecursivelyShared("home"))
		assertVFS(t, v, `
-1 -1 0:0 / / rw - (fstype) (source) rw
0  -1 0:0 / /home rw shared:1 - (fstype) (source) rw
1  0 0:0 / /home/zyga rw shared:2 - (fstype) (source) rw
`)
	})

	t.Run("leaf", func(t *testing.T) {
		v := vfs.NewVFS(fstest.MapFS{"home": &fstest.MapFile{Mode: fs.ModeDir}})
		assertSuccess(t, v.Mount(fstest.MapFS{"zyga": &fstest.MapFile{Mode: fs.ModeDir}}, "home"))
		assertSuccess(t, v.Mount(fstest.MapFS{}, "home/zyga"))
		assertSuccess(t, v.MakeRecursivelyShared("home/zyga"))
		assertVFS(t, v, `
-1 -1 0:0 / / rw - (fstype) (source) rw
0  -1 0:0 / /home rw - (fstype) (source) rw
1  0 0:0 / /home/zyga rw shared:1 - (fstype) (source) rw
`)
	})
}