@@ -10,20 +10,14 @@ import scala.util.Random
10
10
11
11
class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
12
12
13
- protected def testPluginFrontend (frontend : PluginFrontend ): Array [Byte ] = {
14
- val random = new Random ()
15
- val toSend = Array .fill(123 )(random.nextInt(256 ).toByte)
16
- val toReceive = Array .fill(456 )(random.nextInt(256 ).toByte)
17
- val env = new ExtraEnv (secondaryOutputDir = " tmp" )
18
-
19
- val fakeGenerator = new ProtocCodeGenerator {
20
- override def run (request : Array [Byte ]): Array [Byte ] = {
21
- request mustBe (toSend ++ env.toByteArrayAsField)
22
- toReceive
23
- }
24
- }
13
+ protected def testPluginFrontend (
14
+ frontend : PluginFrontend ,
15
+ generator : ProtocCodeGenerator ,
16
+ env : ExtraEnv ,
17
+ request : Array [Byte ]
18
+ ): Array [Byte ] = {
25
19
val (path, state) = frontend.prepare(
26
- fakeGenerator ,
20
+ generator ,
27
21
env
28
22
)
29
23
val actualOutput = new ByteArrayOutputStream ()
@@ -32,7 +26,7 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
32
26
.run(
33
27
new ProcessIO (
34
28
writeInput => {
35
- writeInput.write(toSend )
29
+ writeInput.write(request )
36
30
writeInput.close()
37
31
},
38
32
processOutput => {
@@ -53,4 +47,34 @@ class OsSpecificFrontendSpec extends AnyFlatSpec with Matchers {
53
47
frontend.cleanup(state)
54
48
actualOutput.toByteArray
55
49
}
50
+
51
+ protected def testSuccess (frontend : PluginFrontend ): Unit = {
52
+ val random = new Random ()
53
+ val toSend = Array .fill(123 )(random.nextInt(256 ).toByte)
54
+ val toReceive = Array .fill(456 )(random.nextInt(256 ).toByte)
55
+ val env = new ExtraEnv (secondaryOutputDir = " tmp" )
56
+
57
+ val fakeGenerator = new ProtocCodeGenerator {
58
+ override def run (request : Array [Byte ]): Array [Byte ] = {
59
+ request mustBe (toSend ++ env.toByteArrayAsField)
60
+ toReceive
61
+ }
62
+ }
63
+ val response = testPluginFrontend(frontend, fakeGenerator, env, toSend)
64
+ response mustBe toReceive
65
+ }
66
+
67
+ protected def testFailure (frontend : PluginFrontend ): Unit = {
68
+ val random = new Random ()
69
+ val toSend = Array .fill(123 )(random.nextInt(256 ).toByte)
70
+ val env = new ExtraEnv (secondaryOutputDir = " tmp" )
71
+
72
+ val fakeGenerator = new ProtocCodeGenerator {
73
+ override def run (request : Array [Byte ]): Array [Byte ] = {
74
+ throw new OutOfMemoryError (" test error" )
75
+ }
76
+ }
77
+ val response = testPluginFrontend(frontend, fakeGenerator, env, toSend)
78
+ response.length must be > 0
79
+ }
56
80
}
0 commit comments