3 # Tests of the fuse mount functionality.
13 def test_lostfound(bfuse):
16 lf = bfuse.mnt / "lost+found"
20 assert st.st_mode == 0o40700
25 def test_create(bfuse):
28 path = bfuse.mnt / "file"
30 with util.Timestamp() as ts:
31 fd = os.open(path, os.O_CREAT, 0o700)
40 assert st.st_mode == 0o100700
41 assert st.st_mtime == st.st_ctime
42 assert st.st_mtime == st.st_atime
43 assert ts.contains(st.st_mtime)
46 dst = bfuse.mnt.stat()
47 assert dst.st_mtime == dst.st_ctime
48 assert ts.contains(dst.st_mtime)
53 def test_mkdir(bfuse):
56 path = bfuse.mnt / "dir"
58 with util.Timestamp() as ts:
65 assert st.st_mode == 0o40700
66 assert st.st_mtime == st.st_ctime
67 assert st.st_mtime == st.st_atime
68 assert ts.contains(st.st_mtime)
71 dst = bfuse.mnt.stat()
72 assert dst.st_mtime == dst.st_ctime
73 assert ts.contains(dst.st_mtime)
78 def test_unlink(bfuse):
81 path = bfuse.mnt / "file"
82 path.touch(mode=0o600, exist_ok=False)
84 with util.Timestamp() as ts:
87 assert not path.exists()
90 dst = bfuse.mnt.stat()
91 assert dst.st_mtime == dst.st_ctime
92 assert ts.contains(dst.st_mtime)
97 def test_rmdir(bfuse):
100 path = bfuse.mnt / "dir"
101 path.mkdir(mode=0o700, exist_ok=False)
103 with util.Timestamp() as ts:
106 assert not path.exists()
109 dst = bfuse.mnt.stat()
110 assert dst.st_mtime == dst.st_ctime
111 assert ts.contains(dst.st_mtime)
116 def test_rename(bfuse):
121 path = srcdir / "file"
122 path.touch(mode=0o600, exist_ok=False)
124 destdir = srcdir / "dir"
125 destdir.mkdir(mode=0o700, exist_ok=False)
127 destpath = destdir / "file"
129 path_pre_st = path.stat()
131 with util.Timestamp() as ts:
132 os.rename(path, destpath)
134 assert not path.exists()
135 assert destpath.is_file()
138 src_st = srcdir.stat()
139 assert src_st.st_mtime == src_st.st_ctime
140 assert ts.contains(src_st.st_mtime)
142 dest_st = destdir.stat()
143 assert dest_st.st_mtime == dest_st.st_ctime
144 assert ts.contains(dest_st.st_mtime)
147 path_post_st = destpath.stat()
148 assert path_post_st.st_mtime == path_pre_st.st_mtime
149 assert path_post_st.st_atime == path_pre_st.st_atime
150 assert ts.contains(path_post_st.st_ctime)
155 def test_link(bfuse):
160 path = srcdir / "file"
161 path.touch(mode=0o600, exist_ok=False)
163 destdir = srcdir / "dir"
164 destdir.mkdir(mode=0o700, exist_ok=False)
166 destpath = destdir / "file"
168 path_pre_st = path.stat()
169 srcdir_pre_st = srcdir.stat()
171 with util.Timestamp() as ts:
172 os.link(path, destpath)
175 assert destpath.is_file()
177 # Verify source dir is unchanged.
178 srcdir_post_st = srcdir.stat()
179 assert srcdir_pre_st == srcdir_post_st
182 destdir_st = destdir.stat()
183 assert destdir_st.st_mtime == destdir_st.st_ctime
184 assert ts.contains(destdir_st.st_mtime)
187 path_post_st = path.stat()
188 destpath_post_st = destpath.stat()
189 assert path_post_st == destpath_post_st
191 assert path_post_st.st_mtime == path_pre_st.st_mtime
192 assert path_post_st.st_atime == path_pre_st.st_atime
193 assert ts.contains(path_post_st.st_ctime)
198 def test_write(bfuse):
201 path = bfuse.mnt / "file"
202 path.touch(mode=0o600, exist_ok=False)
206 fd = os.open(path, os.O_WRONLY)
209 with util.Timestamp() as ts:
210 written = os.write(fd, b'test')
216 post_st = path.stat()
217 assert post_st.st_atime == pre_st.st_atime
218 assert post_st.st_mtime == post_st.st_ctime
219 assert ts.contains(post_st.st_mtime)
221 assert path.read_bytes() == b'test'