aboutsummaryrefslogtreecommitdiffhomepage
path: root/hst/fsbind_test.go
blob: 61fc1f2c54a85aed0a0631451bd48aa97ef77887 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package hst_test

import (
	"testing"

	"hakurei.app/container"
	"hakurei.app/container/std"
	"hakurei.app/hst"
)

func TestFSBind(t *testing.T) {
	t.Parallel()

	checkFs(t, []fsTestCase{
		{"nil", (*hst.FSBind)(nil), false, nil, nil, nil, "<invalid>"},
		{"ensure optional", &hst.FSBind{Source: m("/"), Ensure: true, Optional: true},
			false, nil, nil, nil, "<invalid>"},

		{"full", &hst.FSBind{
			Target:   m("/dev"),
			Source:   m("/mnt/dev"),
			Optional: true,
			Device:   true,
		}, true, container.Ops{&container.BindMountOp{
			Source: m("/mnt/dev"),
			Target: m("/dev"),
			Flags:  std.BindWritable | std.BindDevice | std.BindOptional,
		}}, m("/dev"), ms("/mnt/dev"),
			"d+/mnt/dev:/dev"},

		{"full ensure", &hst.FSBind{
			Target: m("/dev"),
			Source: m("/mnt/dev"),
			Ensure: true,
			Device: true,
		}, true, container.Ops{&container.BindMountOp{
			Source: m("/mnt/dev"),
			Target: m("/dev"),
			Flags:  std.BindWritable | std.BindDevice | std.BindEnsure,
		}}, m("/dev"), ms("/mnt/dev"),
			"d-/mnt/dev:/dev"},

		{"full write dev", &hst.FSBind{
			Target: m("/dev"),
			Source: m("/mnt/dev"),
			Write:  true,
			Device: true,
		}, true, container.Ops{&container.BindMountOp{
			Source: m("/mnt/dev"),
			Target: m("/dev"),
			Flags:  std.BindWritable | std.BindDevice,
		}}, m("/dev"), ms("/mnt/dev"),
			"d*/mnt/dev:/dev"},

		{"full write", &hst.FSBind{
			Target: m("/tmp"),
			Source: m("/mnt/tmp"),
			Write:  true,
		}, true, container.Ops{&container.BindMountOp{
			Source: m("/mnt/tmp"),
			Target: m("/tmp"),
			Flags:  std.BindWritable,
		}}, m("/tmp"), ms("/mnt/tmp"),
			"w*/mnt/tmp:/tmp"},

		{"full no flags", &hst.FSBind{
			Target: m("/etc"),
			Source: m("/mnt/etc"),
		}, true, container.Ops{&container.BindMountOp{
			Source: m("/mnt/etc"),
			Target: m("/etc"),
		}}, m("/etc"), ms("/mnt/etc"),
			"*/mnt/etc:/etc"},

		{"nil dst", &hst.FSBind{
			Source: m("/"),
		}, true, container.Ops{&container.BindMountOp{
			Source: m("/"),
			Target: m("/"),
		}}, m("/"), ms("/"),
			"*/"},

		{"special nil target", &hst.FSBind{
			Source:  m("/"),
			Special: true,
		}, false, nil, nil, nil, "<invalid>"},

		{"special bad target", &hst.FSBind{
			Source:  m("/"),
			Target:  m("/var/"),
			Special: true,
		}, false, nil, nil, nil, "<invalid>"},

		{"autoroot pd", &hst.FSBind{
			Target:  m("/"),
			Source:  m("/"),
			Write:   true,
			Special: true,
		}, true, container.Ops{&container.AutoRootOp{
			Host:  m("/"),
			Flags: std.BindWritable,
		}}, m("/"), ms("/"), "autoroot:w"},

		{"autoroot silly", &hst.FSBind{
			Target:  m("/"),
			Source:  m("/etc"),
			Write:   true,
			Special: true,
		}, true, container.Ops{&container.AutoRootOp{
			Host:  m("/etc"),
			Flags: std.BindWritable,
		}}, m("/"), ms("/etc"), "autoroot:w:/etc"},

		{"autoetc", &hst.FSBind{
			Target:  m("/etc/"),
			Source:  m("/etc/"),
			Special: true,
		}, true, container.Ops{
			&container.MkdirOp{Path: m("/etc/"), Perm: 0755},
			&container.BindMountOp{Source: m("/etc/"), Target: m("/etc/.host/:3")},
			&container.AutoEtcOp{Prefix: ":3"},
		}, m("/etc/"), ms("/etc/"), "autoetc:/etc/"},
	})
}