-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileCheckerTest.scala
52 lines (43 loc) · 1.91 KB
/
FileCheckerTest.scala
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
package com.exasol.common.file
import java.io.File
import java.io.IOException
import java.io.UncheckedIOException
import java.nio.file.Files
import org.mockito.Mockito.when
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.mockito.MockitoSugar
class FileCheckerTest extends AnyFunSuite with Matchers with MockitoSugar {
test("temporary file checker checks correct path") {
val fileParent = "/tmp/bfsdefault/bucket1"
val file = new File(fileParent, "/file.txt")
Files.createDirectories(new File(fileParent).toPath())
Files.createFile(file.toPath())
assert(new TemporaryFileChecker().isRegularFile("/tmp/bfsdefault/bucket1/file.txt") === true)
file.delete()
}
test("bucketfs file checker throws when path is missing") {
assert(new BucketFSFileChecker().isRegularFile("/buckets/non-existing/default/file.txt") === false)
}
test("bucketfs file checker throws when path does not start with expected prefix") {
val thrown = intercept[IllegalArgumentException] {
new BucketFSFileChecker().isRegularFile("/var/log/bucket1/file.txt")
}
val message = thrown.getMessage()
assert(message.startsWith("E-IEUCS-12"))
assert(message.contains("Provided path '/var/log/bucket1/file.txt' does not start with expected"))
assert(message.contains("Please make sure that file path start with '/buckets'."))
}
test("bucketfs file checker throws ioexception") {
val file = mock[File]
when(file.getAbsolutePath()).thenReturn("test/path")
when(file.getCanonicalPath()).thenThrow(new IOException())
val thrown = intercept[UncheckedIOException] {
new BucketFSFileChecker().checkStartsWithPath(file)
}
assert(thrown.getMessage().startsWith("E-IEUCS-13: Failed to open path 'test/path'."))
}
class TemporaryFileChecker extends FileChecker {
override final def getLocationPrefix(): String = "/tmp"
}
}