@@ -12,7 +12,7 @@ import io.typestream.testing.avro.buildAuthor
12
12
import io.typestream.testing.konfig.testKonfig
13
13
import kotlinx.coroutines.Dispatchers
14
14
import org.assertj.core.api.Assertions.assertThat
15
- import org.junit.jupiter.api.BeforeEach
15
+ import org.junit.jupiter.api.BeforeAll
16
16
import org.junit.jupiter.api.Nested
17
17
import org.junit.jupiter.api.Test
18
18
import org.junit.jupiter.params.ParameterizedTest
@@ -21,76 +21,27 @@ import org.junit.jupiter.params.provider.MethodSource
21
21
import org.testcontainers.junit.jupiter.Container
22
22
import org.testcontainers.junit.jupiter.Testcontainers
23
23
import java.util.stream.Stream
24
- import kotlin.test.assertNull
25
24
26
25
@Testcontainers
27
26
internal class FileSystemTest {
27
+ companion object {
28
+ private lateinit var fileSystem: FileSystem
28
29
29
- @Container
30
- private val testKafka = RedpandaContainerWrapper ()
31
-
32
- private lateinit var fileSystem: FileSystem
33
-
34
- @BeforeEach
35
- fun beforeEach () {
36
- fileSystem = FileSystem (SourcesConfig (testKonfig(testKafka)), Dispatchers .IO )
37
- }
38
-
39
- @Test
40
- fun `expands paths correctly` () {
41
- fileSystem.use {
42
- assertThat(fileSystem.expandPath(" dev" , " /" )).isEqualTo(" /dev" )
43
- assertThat(fileSystem.expandPath(" dev/" , " /" )).isEqualTo(" /dev" )
44
- assertThat(fileSystem.expandPath(" kafka" , " /dev" )).isEqualTo(" /dev/kafka" )
45
- assertThat(fileSystem.expandPath(" /dev/kafka" , " /" )).isEqualTo(" /dev/kafka" )
46
- assertThat(fileSystem.expandPath(" /dev/kafka" , " /dev" )).isEqualTo(" /dev/kafka" )
47
- assertThat(fileSystem.expandPath(" " , " /" )).isEqualTo(" /" )
48
- assertThat(fileSystem.expandPath(" .." , " /dev" )).isEqualTo(" /" )
49
- assertThat(fileSystem.expandPath(" .." , " /dev/kafka" )).isEqualTo(" /dev" )
50
- assertNull(fileSystem.expandPath(" dev/whatever" , " /" ))
51
- }
52
- }
53
-
54
- @Nested
55
- inner class EncodingRules {
56
- @Test
57
- fun `infers simple encoding` () {
58
- fileSystem.use {
59
- testKafka.produceRecords(" authors" , buildAuthor(" Octavia E. Butler" ))
60
-
61
- fileSystem.refresh()
62
-
63
- val dataCommand = Cat (listOf (Expr .BareWord (" /dev/kafka/local/topics/authors" )))
64
-
65
- dataCommand.dataStreams.add(author())
66
-
67
- assertThat(fileSystem.inferEncoding(dataCommand)).isEqualTo(Encoding .AVRO )
68
- }
69
- }
70
-
71
- @Test
72
- fun `infers pipeline encoding` () {
73
- fileSystem.use {
74
- testKafka.produceRecords(" authors" , buildAuthor(" Emily St. John Mandel" ))
75
-
76
- fileSystem.refresh()
77
-
78
- val cat = Cat (listOf (Expr .BareWord (" /dev/kafka/local/topics/authors" )))
79
-
80
- cat.dataStreams.add(author())
30
+ @Container
31
+ private val testKafka = RedpandaContainerWrapper ()
81
32
82
- val grep = Grep (listOf (Expr .BareWord (" Mandel" )))
33
+ @JvmStatic
34
+ @BeforeAll
35
+ fun beforeAll () {
36
+ fileSystem = FileSystem (SourcesConfig (testKonfig(testKafka)), Dispatchers .IO )
83
37
84
- val pipeline = Pipeline ( listOf (cat, grep ))
38
+ testKafka.produceRecords( " authors " , buildAuthor( " Octavia E. Butler " ))
85
39
86
- assertThat(fileSystem.inferEncoding(pipeline)).isEqualTo(Encoding .AVRO )
87
- }
40
+ fileSystem.refresh()
88
41
}
89
- }
90
42
91
- companion object {
92
43
@JvmStatic
93
- fun incompletePaths (): Stream <Arguments > = Stream .of(
44
+ fun completePathCases (): Stream <Arguments > = Stream .of(
94
45
Arguments .of(" d" , " /" , listOf (" dev/" )),
95
46
Arguments .of(" /d" , " /" , listOf (" /dev/" )),
96
47
Arguments .of(" ka" , " /dev" , listOf (" kafka/" )),
@@ -105,26 +56,55 @@ internal class FileSystemTest {
105
56
)
106
57
),
107
58
)
59
+
60
+ @JvmStatic
61
+ fun expandPathCases (): Stream <Arguments > = Stream .of(
62
+ Arguments .of(" dev" , " /" , " /dev" ),
63
+ Arguments .of(" dev/" , " /" , " /dev" ),
64
+ Arguments .of(" kafka" , " /dev" , " /dev/kafka" ),
65
+ Arguments .of(" /dev/kafka" , " /" , " /dev/kafka" ),
66
+ Arguments .of(" /dev/kafka" , " /dev" , " /dev/kafka" ),
67
+ Arguments .of(" " , " /" , " /" ),
68
+ Arguments .of(" .." , " /dev" , " /" ),
69
+ Arguments .of(" .." , " /dev/kafka" , " /dev" ),
70
+ Arguments .of(" dev/whatever" , " /" , null ),
71
+ )
108
72
}
109
73
110
74
@ParameterizedTest
111
- @MethodSource(" incompletePaths " )
75
+ @MethodSource(" completePathCases " )
112
76
fun `completes correctly` (incompletePath : String , pwd : String , suggestions : List <String >) {
113
- fileSystem.use {
114
- assertThat(fileSystem.completePath(incompletePath, pwd)).contains(* suggestions.toTypedArray())
115
- }
77
+ assertThat(fileSystem.completePath(incompletePath, pwd)).contains(* suggestions.toTypedArray())
116
78
}
117
79
118
- @Test
119
- fun `only completes directories with trailing slash` () {
120
- fileSystem.use {
121
- testKafka.produceRecords(" authors" , buildAuthor(" Chimamanda Ngozi Adichie" ))
80
+ @ParameterizedTest
81
+ @MethodSource(" expandPathCases" )
82
+ fun `expands paths correctly` (path : String , pwd : String , expected : String? ) {
83
+ assertThat(fileSystem.expandPath(path, pwd)).isEqualTo(expected)
84
+ }
122
85
123
- fileSystem.refresh()
86
+ @Nested
87
+ inner class EncodingRules {
88
+ @Test
89
+ fun `infers simple encoding` () {
90
+ val dataCommand = Cat (listOf (Expr .BareWord (" /dev/kafka/local/topics/authors" )))
91
+
92
+ dataCommand.dataStreams.add(author())
93
+
94
+ assertThat(fileSystem.inferEncoding(dataCommand)).isEqualTo(Encoding .AVRO )
95
+ }
96
+
97
+ @Test
98
+ fun `infers pipeline encoding` () {
99
+ val cat = Cat (listOf (Expr .BareWord (" /dev/kafka/local/topics/authors" )))
100
+
101
+ cat.dataStreams.add(author())
102
+
103
+ val grep = Grep (listOf (Expr .BareWord (" Butler" )))
104
+
105
+ val pipeline = Pipeline (listOf (cat, grep))
124
106
125
- assertThat(
126
- fileSystem.completePath(" dev/kafka/local/topics/a" , " /" )
127
- ).contains(" dev/kafka/local/topics/authors" )
107
+ assertThat(fileSystem.inferEncoding(pipeline)).isEqualTo(Encoding .AVRO )
128
108
}
129
109
}
130
110
}
0 commit comments