-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathFileSystemResultsWriterTest.java
More file actions
138 lines (112 loc) · 5.68 KB
/
FileSystemResultsWriterTest.java
File metadata and controls
138 lines (112 loc) · 5.68 KB
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
/*
* Copyright 2016-2026 Qameta Software Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.qameta.allure;
import io.qameta.allure.model.TestResult;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
import static io.qameta.allure.FileSystemResultsWriter.generateTestResultName;
import static io.qameta.allure.test.ThreadLocalEnhancedRandom.current;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author charlie (Dmitry Baev).
*/
public class FileSystemResultsWriterTest {
@Test
void shouldNotFailIfNoResultsDirectory(@TempDir final Path folder) {
Path resolve = folder.resolve("some-directory");
FileSystemResultsWriter writer = new FileSystemResultsWriter(resolve);
final TestResult testResult = current().nextObject(TestResult.class, "steps");
writer.write(testResult);
}
@Test
void shouldWriteTestResult(@TempDir final Path folder) {
FileSystemResultsWriter writer = new FileSystemResultsWriter(folder);
final String uuid = UUID.randomUUID().toString();
final TestResult testResult = current().nextObject(TestResult.class, "steps").setUuid(uuid);
writer.write(testResult);
final String fileName = generateTestResultName(uuid);
assertThat(folder)
.isDirectory();
assertThat(folder.resolve(fileName))
.isRegularFile();
}
@Test
void shouldPreserveOldResultsWhenCleanIsDisabled(@TempDir final Path folder) throws IOException {
Path existingFile = folder.resolve("existing-result.json");
Files.writeString(existingFile, "{}");
FileSystemResultsWriter writer = new FileSystemResultsWriter(folder, false, true);
final String uuid = UUID.randomUUID().toString();
final TestResult testResult = current().nextObject(TestResult.class, "steps").setUuid(uuid);
writer.write(testResult);
assertThat(existingFile).exists();
assertThat(folder.resolve(generateTestResultName(uuid))).exists();
}
@Test
void shouldCleanDirectoryWhenCleanBeforeRunEnabled(@TempDir final Path folder) throws IOException {
Path existingFile = folder.resolve("existing-result.json");
Files.writeString(existingFile, "{}");
FileSystemResultsWriter writer = new FileSystemResultsWriter(folder, true, true);
final String uuid = UUID.randomUUID().toString();
final TestResult testResult = current().nextObject(TestResult.class, "steps").setUuid(uuid);
writer.write(testResult);
assertThat(existingFile).doesNotExist();
assertThat(folder.resolve(generateTestResultName(uuid))).exists();
}
@Test
void shouldCleanOnlyOnceWhenCleanOnlyOnceEnabled(@TempDir final Path folder) throws IOException {
Path existingFile = folder.resolve("existing-result.json");
Files.writeString(existingFile, "{}");
FileSystemResultsWriter writer = new FileSystemResultsWriter(folder, true, true);
final String uuid1 = UUID.randomUUID().toString();
final TestResult testResult1 = current().nextObject(TestResult.class, "steps").setUuid(uuid1);
writer.write(testResult1);
final String uuid2 = UUID.randomUUID().toString();
final TestResult testResult2 = current().nextObject(TestResult.class, "steps").setUuid(uuid2);
writer.write(testResult2);
assertThat(folder.resolve(generateTestResultName(uuid1))).exists();
assertThat(folder.resolve(generateTestResultName(uuid2))).exists();
}
@Test
void shouldCleanOnEveryFirstWriteWhenCleanOnlyOnceDisabled(@TempDir final Path folder) throws IOException {
FileSystemResultsWriter writer1 = new FileSystemResultsWriter(folder, true, false);
final String uuid1 = UUID.randomUUID().toString();
final TestResult testResult1 = current().nextObject(TestResult.class, "steps").setUuid(uuid1);
writer1.write(testResult1);
Path intermediateFile = folder.resolve("intermediate-result.json");
Files.writeString(intermediateFile, "{}");
FileSystemResultsWriter writer2 = new FileSystemResultsWriter(folder, true, false);
final String uuid2 = UUID.randomUUID().toString();
final TestResult testResult2 = current().nextObject(TestResult.class, "steps").setUuid(uuid2);
writer2.write(testResult2);
assertThat(intermediateFile).doesNotExist();
assertThat(folder.resolve(generateTestResultName(uuid2))).exists();
}
@Test
void shouldNotDeleteDirectoryItself(@TempDir final Path folder) throws IOException {
Path existingFile = folder.resolve("existing-result.json");
Files.writeString(existingFile, "{}");
FileSystemResultsWriter writer = new FileSystemResultsWriter(folder, true, true);
final String uuid = UUID.randomUUID().toString();
final TestResult testResult = current().nextObject(TestResult.class, "steps").setUuid(uuid);
writer.write(testResult);
assertThat(folder).isDirectory();
assertThat(folder.resolve(generateTestResultName(uuid))).exists();
}
}