/
VirtualFSTest.java
451 lines (390 loc) · 9.7 KB
/
VirtualFSTest.java
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
package com.laytonsmith.PureUtilities.VirtualFS;
import com.laytonsmith.PureUtilities.Common.FileUtil;
import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
*
*
*/
public class VirtualFSTest {
public VirtualFSTest() {
}
static final File ROOT = new File("./VirtualFS");
static final File EXTERNAL = new File("./OutsideVFS");
static final File SETTINGS_FILE = new File(ROOT, ".vfsmeta/settings.yml");
@BeforeClass
public static void setUpClass() {
ROOT.mkdirs();
EXTERNAL.mkdirs();
}
@AfterClass
public static void tearDownClass() {
FileUtil.recursiveDelete(ROOT);
FileUtil.recursiveDelete(EXTERNAL);
assertFalse(ROOT + " was not deleted!", ROOT.exists());
assertFalse(EXTERNAL + " was not deleted!", EXTERNAL.exists());
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Convenience method to write the given settings to file.
*
* @param settings
*/
private void writeSettings(String settings) throws IOException {
FileUtil.write(settings, SETTINGS_FILE);
}
private VirtualFileSystem setupVFS(String settings) throws IOException {
writeSettings(settings);
return new VirtualFileSystem(ROOT, new VirtualFileSystemSettings(SETTINGS_FILE));
}
/**
* This test sees if the VFS starts up correctly, that is, the file system is created with all the appropriate meta
* files.
*
* @throws Exception
*/
@Test
@SuppressWarnings("ResultOfObjectAllocationIgnored")
public void virtualFSSetup() throws Exception {
String settingsString = "'**': {\n"
+ " hidden: true,\n"
+ " readonly: true\n"
+ "}\n";
writeSettings(settingsString);
new VirtualFileSystem(ROOT, new VirtualFileSystemSettings(SETTINGS_FILE));
assertTrue(FileUtil.read(SETTINGS_FILE).contains(VirtualFileSystemSettings.getDefaultSettingsString()));
assertTrue(FileUtil.read(SETTINGS_FILE).contains(settingsString));
}
/**
* This simple test sees if a file writes to the appropriate location, and can be re-read with a read call.
*
* @throws Exception
*/
@Test
@Ignore("TODO")
public void testWriteReadWithNewFile() throws Exception {
String fileText = "This is the text in the file";
VirtualFileSystem vfs = new VirtualFileSystem(ROOT, null);
String fname = "testWriteReadWithNewFile.txt";
VirtualFile vf = new VirtualFile("/" + fname);
File realFile = new File(ROOT, fname);
vfs.writeUTFString(vf, fileText);
assertEquals(fileText, FileUtil.read(realFile));
assertEquals(fileText, vfs.readUTFString(vf));
}
private void testGlob(VirtualGlob glob, boolean expectMatch, VirtualFile... files) {
for(VirtualFile f : files) {
assertEquals(expectMatch, glob.matches(f));
}
}
@Test
@Ignore("TODO")
public void testGlobbingWorks() throws Exception {
VirtualFile v1 = new VirtualFile("/top.txt");
VirtualFile v12 = new VirtualFile("/top.txtt");
VirtualFile v13 = new VirtualFile("/top.tx");
VirtualFile v2 = new VirtualFile("/top.ms");
VirtualFile v3 = new VirtualFile("/dir/middle.txt");
VirtualFile v4 = new VirtualFile("/dir/middle.ms");
VirtualFile v42 = new VirtualFile("/dir2/test.txt");
VirtualFile v43 = new VirtualFile("/dir3/test.txt");
VirtualFile v5 = new VirtualFile("/dir/dir/bottom.txt");
VirtualFile v52 = new VirtualFile("/dir/dir/test.txt");
VirtualFile v6 = new VirtualFile("/dir/dir/bottom.ms");
VirtualGlob glob1 = new VirtualGlob("**");
VirtualGlob glob2 = new VirtualGlob("**.ms");
VirtualGlob glob3 = new VirtualGlob("/top.txtt?");
VirtualGlob glob4 = new VirtualGlob("/*/test.txt");
VirtualGlob glob5 = new VirtualGlob("/**/test.txt");
testGlob(glob1, true, v1, v2, v3, v4, v5, v6);
testGlob(glob2, true, v2, v4, v6);
testGlob(glob2, false, v1, v3, v5);
testGlob(glob3, true, v1);
testGlob(glob3, false, v2);
testGlob(glob3, true, v1, v12);
testGlob(glob3, false, v13);
testGlob(glob4, true, v42, v43);
testGlob(glob4, false, v52);
testGlob(glob5, true, v42, v43, v52);
testGlob(glob5, false, v1, v2, v3, v4, v5, v6);
}
@Test
@Ignore("TODO")
public void testCordonedOffIsGlobal() throws Exception {
VirtualFileSystemSettings s = new VirtualFileSystemSettings("'**': {\n cordoned-off: true\n}\n");
assertTrue(s.isCordonedOff());
VirtualFileSystemSettings s2 = new VirtualFileSystemSettings("");
assertFalse(s2.isCordonedOff());
try {
VirtualFileSystemSettings s3 = new VirtualFileSystemSettings("'directory': {\n cordoned-off: true\n}\n");
fail();
} catch (IllegalArgumentException ex) {
// pass
}
}
/**
* This test sees if a file that is created from an outside process cannot be read, since it is not in the manifest
*
* @throws Exception
*/
@Test
@Ignore("TODO")
public void testCordonedFileNotFound() throws Exception {
String settingsString = "'**': {\n"
+ " cordoned-off: true\n"
+ "}\n";
VirtualFileSystem s = setupVFS(settingsString);
String fn = "testCordonedFileNotFound";
File real = new File(ROOT, fn);
real.createNewFile();
assertTrue(real.exists());
VirtualFile virtual = new VirtualFile("/" + fn);
assertFalse(s.exists(virtual));
}
/**
* This test sees if writing to a file that was created from an outside process fails, since it is not in the
* manifest.
*
* @throws Exception
*/
@Test
@Ignore
public void testCordonedOffTryToWriteOverExternalFile() throws Exception {
// Required for minimum product
}
/**
* This tests the trivial case where a new file is successfully created in an empty spot.
*
* @throws Exception
*/
@Test
@Ignore
public void testCordonedOffNewFileCreation() throws Exception {
// Required for minimum product
}
/**
* This ensures that reads and writes to the meta directory always fail.
*
* @throws Exception
*/
@Test
@Ignore
public void testMetaFileReadWriteFails() throws Exception {
// Required for minimum product
}
/**
* This test verifies that reading and writing above the file system will not work.
*
* @throws Exception
*/
@Test
@Ignore
public void testReadWriteAboveFSFails() throws Exception {
// Required for minimum product
}
/**
* This ensures that symlinks work with plain local files.
*
* @throws Exception
*/
@Test
@Ignore
public void testSymlink() throws Exception {
}
/**
* This ensures that symlinks to a remote file system work.
*
* @throws Exception
*/
@Test
@Ignore
public void testSSHSymlink() throws Exception {
}
/**
* This ensures that listing files works properly
*
* @throws Exception
*/
@Test
@Ignore
public void testList() throws Exception {
// Required for minimum product
}
/**
* This ensures file deletion works.
*
* @throws Exception
*/
@Test
@Ignore
public void testDelete() throws Exception {
// Required for minimum product
}
/**
* Ensures file existance checking works.
*
* @throws Exception
*/
@Test
@Ignore
public void testExists() throws Exception {
// Required for minimum product
}
/**
* Tests isAbsolute
*
* @throws Exception
*/
@Test
@Ignore
public void testIsAbsolute() throws Exception {
}
/**
* Tests isDirectory
*
* @throws Exception
*/
@Test
@Ignore
public void testIsDirectory() throws Exception {
}
/**
* Tests isFile
*
* @throws Exception
*/
@Test
@Ignore
public void testIsFile() throws Exception {
}
/**
* Tests mkdirs
*
* @throws Exception
*/
@Test
@Ignore
public void testMkDirs() throws Exception {
}
/**
* Tests mkdir
*
* @throws Exception
*/
@Test
@Ignore
public void testMkDir() throws Exception {
// Required for minimum product
}
/**
* Tests creating an empty file
*
* @throws Exception
*/
@Test
@Ignore
public void testCreateEmptyFile() throws Exception {
}
/**
* Tests creating a temp file.
*
* @throws Exception
*/
@Test
@Ignore
public void testCreateTmpFile() throws Exception {
}
/**
* Ensures that a folder that is hidden will not show up
*
* @throws Exception
*/
@Test
@Ignore
public void testHiddenFileNotShowing() throws Exception {
}
/**
* Ensures that quotas cannot be exceeded
*
* @throws Exception
*/
@Test
@Ignore
public void testQuota() throws Exception {
}
/**
* Ensures that a read only file cannot be written to
*
* @throws Exception
*/
@Test
@Ignore
public void testReadOnly() throws Exception {
// Required for minimum product
}
/**
* Ensures that folder depth cannot be exceeded if a restriction is in place.
*
* @throws Exception
*/
@Test
@Ignore
public void testFolderDepth() throws Exception {
}
/**
* Ensures globs match correctly
*
* @throws Exception
*/
@Test
@Ignore
public void testGlobMatching() throws Exception {
}
/**
* Tests basic symlinking, map one file to another.
*
* @throws Exception
*/
@Test
@Ignore
public void testBasicSymlink() throws Exception {
// Required for minimum product
}
/**
* This test ensures that a symlink to deeper in the file system works, and it also tests to make sure that it can
* in fact go up past the "root" of the symlink, as long as ultimately it stays inside the file system.
*
* @throws Exception
*/
@Test
@Ignore
public void testSymlinkDown() throws Exception {
// Required for minimum product
}
/**
* This test ensures that a symlink to a folder completely out of the file system works, and also ensures that it
* can't go up past the "root" of the symlink at all.
*
* @throws Exception
*/
@Test
@Ignore
public void testSymlinkOther() throws Exception {
// Required for minimum product
}
}