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