blob: 6961efc159c48551f90def60e9a22c16b6053b66 (
plain) (
blame)
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
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.io;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.nio.file.Path;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class FileSystemTest {
@Rule
public final TemporaryFolder folder = new TemporaryFolder();
private Path root;
private Path path;
private final FileSystem fileSystem = new FileSystem();
@Before
public void setUp() throws Exception {
root = folder.getRoot().toPath();
path = folder.newFile().toPath();
}
@Test
public void isDirectory() throws Exception {
assertTrue(fileSystem.isDirectory(root));
assertFalse(fileSystem.isDirectory(path));
}
@Test
public void isRegularFile() throws Exception {
assertTrue(fileSystem.isRegularFile(path));
assertFalse(fileSystem.isRegularFile(root));
}
@Test
public void createDirectory() throws Exception {
Path dir = root.resolve("subdir");
fileSystem.createDirectory(dir);
assertTrue(fileSystem.isDirectory(dir));
}
@Test
public void utf8FileIO() throws Exception {
String original = "foo\nbar\n";
Path path = root.resolve("example.txt");
fileSystem.writeUtf8File(path, original);
String fromFile = fileSystem.readUtf8File(path);
assertEquals(original, fromFile);
}
@Test
public void permissions() throws Exception {
String expectedPermissions = "rwxr-x---";
fileSystem.setPermissions(path, expectedPermissions);
assertEquals(expectedPermissions, fileSystem.getPermissions(path));
}
@Test(expected = IllegalArgumentException.class)
public void badPermissionsString() {
fileSystem.setPermissions(path, "abcdefghi");
}
@Test
public void owner() throws Exception {
String owner = fileSystem.getOwner(path);
fileSystem.setOwner(path, owner);
}
@Test
public void group() throws Exception {
String group = fileSystem.getGroup(path);
fileSystem.setGroup(path, group);
}
}
|