Skip to content

Commit 9c31233

Browse files
fs: create dir, delete dir (#784)
1 parent e6361ac commit 9c31233

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scenarios.fs
2+
3+
import static org.testingisdocumenting.webtau.WebTauGroovyDsl.*
4+
5+
scenario('create and delete directory') {
6+
def dir = fs.createDir('fs-new-dir')
7+
fs.copy('data/message.txt', dir)
8+
9+
fs.textContent(dir.resolve('message.txt')).should == 'message inside file'
10+
11+
fs.deleteDir('fs-new-dir')
12+
13+
fs.exists(dir).should == false
14+
fs.exists(dir.resolve('message.txt')).should == false
15+
}

webtau-feature-testing/src/test/groovy/org/testingisdocumenting/webtau/featuretesting/WebTauFileSystemFeaturesTest.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class WebTauFileSystemFeaturesTest {
3232
runCli('copy.groovy', 'webtau.cfg.groovy')
3333
}
3434

35+
@Test
36+
void "dirs"() {
37+
runCli('dirs.groovy', 'webtau.cfg.groovy')
38+
}
39+
3540
private static void runCli(String testName, String configFileName, String... additionalArgs) {
3641
testRunner.runCli("scenarios/fs/$testName",
3742
configFileName.isEmpty() ? "" : "scenarios/fs/$configFileName", additionalArgs)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"scenarioDetails" : [ {
3+
"scenario" : "create and delete directory",
4+
"shortContainerId" : "dirs.groovy",
5+
"stepsSummary" : {
6+
"numberOfSuccessful" : 4
7+
}
8+
} ],
9+
"exitCode" : 0
10+
}

webtau-filesystem/src/main/java/org/testingisdocumenting/webtau/fs/FileSystem.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,53 @@ public void copy(Path src, Path dest) {
8080
step.execute(StepReportOptions.REPORT_ALL);
8181
}
8282

83+
public boolean exists(Path path) {
84+
return Files.exists(path);
85+
}
86+
87+
public boolean exists(String path) {
88+
return exists(Paths.get(path));
89+
}
90+
91+
public Path createDir(String dir) {
92+
return createDir(Paths.get(dir));
93+
}
94+
95+
public Path createDir(Path dir) {
96+
Path fullDirPath = fullPath(dir);
97+
98+
WebTauStep step = WebTauStep.createStep(null,
99+
tokenizedMessage(action("creating"), classifier("dir"), urlValue(dir.toString())),
100+
() -> tokenizedMessage(action("created"), classifier("dir"), urlValue(fullDirPath.toAbsolutePath().toString())),
101+
() -> {
102+
try {
103+
Files.createDirectory(fullDirPath);
104+
return fullDirPath;
105+
} catch (IOException e) {
106+
throw new RuntimeException(e);
107+
}
108+
});
109+
110+
return step.execute(StepReportOptions.REPORT_ALL);
111+
}
112+
113+
public void deleteDir(String dir) {
114+
deleteDir(Paths.get(dir));
115+
}
116+
117+
public void deleteDir(Path dir) {
118+
Path fullDirPath = fullPath(dir);
119+
120+
WebTauStep step = WebTauStep.createStep(null,
121+
tokenizedMessage(action("deleting"), classifier("dir"), urlValue(dir.toString())),
122+
() -> tokenizedMessage(action("deleted"), classifier("dir"), urlValue(fullDirPath.toAbsolutePath().toString())),
123+
() -> {
124+
FileUtils.deleteQuietly(fullDirPath.toFile());
125+
});
126+
127+
step.execute(StepReportOptions.REPORT_ALL);
128+
}
129+
83130
public FileTextContent textContent(Path path) {
84131
return new FileTextContent(path);
85132
}

0 commit comments

Comments
 (0)