-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathRunModesSpec.purs
1405 lines (1283 loc) · 58.1 KB
/
RunModesSpec.purs
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module Presto.Backend.RunModesSpec where
import Data.Ord
import Control.Monad.Aff (Aff)
import Control.Monad.Aff.AVar (AVAR, AVar, makeVar, readVar)
import Control.Monad.Aff.Class (liftAff)
import Control.Monad.Eff.Exception (error, message)
import Control.Monad.Error.Class (throwError)
import Control.Monad.Except.Trans (runExceptT)
import Control.Monad.Reader.Trans (runReaderT)
import Control.Monad.State.Trans (runStateT)
import Data.Array (length, index)
import Data.Either (Either(Left, Right), isRight)
import Data.Foreign (Foreign, F)
import Data.Foreign.Class (class Decode, class Encode)
import Data.Foreign.Generic (encodeJSON, decodeJSON)
import Data.Foreign.Generic.EnumEncoding (class GenericDecodeEnum, class GenericEncodeEnum, genericDecodeEnum, genericEncodeEnum)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show as GShow
import Data.Maybe (Maybe(Nothing, Just))
import Data.StrMap as StrMap
import Data.Traversable (traverse)
import Data.Tuple (Tuple(..))
import Debug.Trace (spy)
import Prelude (class Eq, class Show, Unit, (<$>), bind, discard, pure, show, unit, ($), (*>), (<>), (==), id)
import Presto.Backend.Flow (BackendFlow, BackendFlowCommands(..), callAPI, callAPIGeneric, doAffRR, forkFlow, forkFlow', generateGUID, generateGUID', getDBConn, getOption, log, runSysCmd, setOption, throwException)
import Presto.Backend.Language.Types.DB (MockedSqlConn(MockedSqlConn), SqlConn(MockedSql))
import Presto.Backend.Playback.Entries (CallAPIEntry(..), DoAffEntry(..), LogEntry(..), RunSysCmdEntry(..))
import Presto.Backend.Playback.Types (RecordingEntries, EntryReplayingMode(..), GlobalReplayingMode(..), PlaybackError(..), PlaybackErrorType(..), RecordingEntry(..))
import Presto.Backend.Runtime.Interpreter (RunningMode(..), runBackend)
import Presto.Backend.Runtime.Types (Connection(..), BackendRuntime(..), RunningMode(..), KVDBRuntime(..))
import Presto.Backend.Types.API (class RestEndpoint, APIResult, Request(..), Headers(..), Response(..), ErrorPayload(..), Method(..), defaultDecodeResponse)
import Presto.Backend.Types.Options (class OptionEntity)
import Presto.Core.Utils.Encoding (defaultEncode, defaultDecode)
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual, fail)
defaultEnumDecode :: forall a b. Generic a b => GenericDecodeEnum b => Foreign -> F a
defaultEnumDecode x = genericDecodeEnum { constructorTagTransform: id } x
defaultEnumEncode :: forall a b. Generic a b => GenericEncodeEnum b => a -> Foreign
defaultEnumEncode x = genericEncodeEnum { constructorTagTransform: id } x
data Gateway = GwA | GwB | GwC
data GatewayKey = GatewayKey String
derive instance genericGatewayKey :: Generic GatewayKey _
instance decodeGatewaykey :: Decode GatewayKey where decode = defaultDecode
instance encodeGatewaykey :: Encode GatewayKey where encode = defaultEncode
derive instance eqGateway :: Eq Gateway
derive instance ordGateway :: Ord Gateway
derive instance genericGateway :: Generic Gateway _
instance showGateway :: Show Gateway where show = GShow.genericShow
instance decodeGateway :: Decode Gateway where decode = defaultEnumDecode
instance encodeGateway :: Encode Gateway where encode = defaultEnumEncode
instance optionGateway :: OptionEntity GatewayKey Gateway where
data SomeRequest = SomeRequest
{ code :: Int
, number :: Number
}
data SomeResponse = SomeResponse
{ code :: Int
, string :: String
}
type SomeGenericResponse = Either (Response ErrorPayload) SomeResponse
derive instance genericSomeRequest :: Generic SomeRequest _
derive instance eqSomeRequest :: Eq SomeRequest
instance showSomeRequest :: Show SomeRequest where show = GShow.genericShow
instance decodeSomeRequest :: Decode SomeRequest where decode = defaultDecode
instance encodeSomeRequest :: Encode SomeRequest where encode = defaultEncode
derive instance genericSomeResponse :: Generic SomeResponse _
derive instance eqSomeResponse :: Eq SomeResponse
instance showSomeResponse :: Show SomeResponse where show = GShow.genericShow
instance decodeSomeResponse :: Decode SomeResponse where decode = defaultDecode
instance encodeSomeResponse :: Encode SomeResponse where encode = defaultEncode
instance someRestEndpoint :: RestEndpoint SomeRequest SomeResponse where
makeRequest r@(SomeRequest req) h = Request
{ method : GET
, url : show req.code
, payload : encodeJSON r
, headers : h
}
-- You can spy the values going through the function:
-- decodeResponse resp = const (defaultDecodeResponse resp) $ spy resp
decodeResponse = defaultDecodeResponse
logRunner :: forall a. String -> a -> Aff _ Unit
logRunner tag value = pure (spy tag) *> pure (spy value) *> pure unit
failingLogRunner :: forall a. String -> a -> Aff _ Unit
failingLogRunner tag value = throwError $ error "Logger should not be called."
failingApiRunner :: forall e. Request -> Aff e String
failingApiRunner _ = throwError $ error "API Runner should not be called."
-- TODO: lazy?
failingAffRunner :: forall a. Aff _ a -> Aff _ a
failingAffRunner _ = throwError $ error "Aff Runner should not be called."
apiRunner :: forall e. Request -> Aff e String
apiRunner r@(Request req)
| req.url == "1" = pure $ encodeJSON $ SomeResponse { code: 1, string: "Hello there!" }
apiRunner r
| true = pure $ encodeJSON $ Response
{ code: 400
, status: "Unknown request: " <> encodeJSON r
, response: ErrorPayload
{ error: true
, errorMessage: "Unknown request: " <> encodeJSON r
, userMessage: "Unknown request"
}
}
-- TODO: lazy?
affRunner :: forall a. Aff _ a -> Aff _ a
affRunner aff = aff
optionsV :: StrMap.StrMap String
optionsV = StrMap.insert (encodeJSON $ GatewayKey "explicitGWB") (encodeJSON GwB) $ StrMap.singleton (encodeJSON $ GatewayKey "explicitGWA") "\"GwA\""
mkOptions = makeVar optionsV
emptyHeaders :: Headers
emptyHeaders = Headers []
logScript :: BackendFlow Unit Unit Unit
logScript = do
log "logging1" "try1"
log "logging2" "try2"
log1 = "{\"contents\":{\"tag\":\"logging1\",\"message\":\"\\\"try1\\\"\"},\"tag\":\"LogEntry\"}"
log2 = "{\"contents\":{\"tag\":\"logging2\",\"message\":\"\\\"try2\\\"\"},\"tag\":\"LogEntry\"}"
logScript' :: BackendFlow Unit Unit Unit
logScript' = do
log "logging1.1" "try3 is hitting actual LogRunner"
log "logging2.1" "try4 is hitting actual LogRunner"
callAPIScript :: BackendFlow Unit Unit (Tuple (APIResult SomeResponse) (APIResult SomeResponse))
callAPIScript = do
eRes1 <- callAPI emptyHeaders $ SomeRequest { code: 1, number: 1.0 }
eRes2 <- callAPI emptyHeaders $ SomeRequest { code: 2, number: 2.0 }
pure $ Tuple eRes1 eRes2
callAPIGenericScript :: BackendFlow Unit Unit (Tuple (APIResult SomeGenericResponse) (APIResult SomeGenericResponse))
callAPIGenericScript = do
eRes1 <- callAPIGeneric emptyHeaders $ SomeRequest { code: 1, number: 1.0 }
eRes2 <- callAPIGeneric emptyHeaders $ SomeRequest { code: 2, number: 2.0 }
pure $ Tuple eRes1 eRes2
capi1 = "{\"contents\":{\"jsonResult\":{\"contents\":{\"string\":\"Hello there!\",\"code\":1},\"tag\":\"RightEx\"},\"jsonRequest\":{\"url\":\"1\",\"payload\":\"{\\\"number\\\":1,\\\"code\\\":1}\",\"method\":{\"tag\":\"GET\"},\"headers\":[]}},\"tag\":\"CallAPIEntry\"}"
capi2 = "{\"contents\":{\"jsonResult\":{\"contents\":{\"status\":\"Unknown request: {\\\"url\\\":\\\"2\\\",\\\"payload\\\":\\\"{\\\\\\\"number\\\\\\\":2,\\\\\\\"code\\\\\\\":2}\\\",\\\"method\\\":{\\\"tag\\\":\\\"GET\\\"},\\\"headers\\\":[]}\",\"response\":{\"userMessage\":\"Unknown request\",\"errorMessage\":\"Unknown request: {\\\"url\\\":\\\"2\\\",\\\"payload\\\":\\\"{\\\\\\\"number\\\\\\\":2,\\\\\\\"code\\\\\\\":2}\\\",\\\"method\\\":{\\\"tag\\\":\\\"GET\\\"},\\\"headers\\\":[]}\",\"error\":true},\"code\":400},\"tag\":\"LeftEx\"},\"jsonRequest\":{\"url\":\"2\",\"payload\":\"{\\\"number\\\":2,\\\"code\\\":2}\",\"method\":{\"tag\":\"GET\"},\"headers\":[]}},\"tag\":\"CallAPIEntry\"}"
capig1 = "{\"contents\":{\"jsonResult\":{\"contents\":{\"string\":\"Hello there!\",\"code\":1},\"tag\":\"RightEx\"},\"jsonRequest\":{\"url\":\"1\",\"payload\":\"{\\\"number\\\":1,\\\"code\\\":1}\",\"method\":{\"tag\":\"GET\"},\"headers\":[]}},\"tag\":\"CallAPIGenericEntry\"}"
capig2 = "{\"contents\":{\"jsonResult\":{\"contents\":{\"status\":\"Unknown request: {\\\"url\\\":\\\"2\\\",\\\"payload\\\":\\\"{\\\\\\\"number\\\\\\\":2,\\\\\\\"code\\\\\\\":2}\\\",\\\"method\\\":{\\\"tag\\\":\\\"GET\\\"},\\\"headers\\\":[]}\",\"response\":{\"userMessage\":\"Unknown request\",\"errorMessage\":\"Unknown request: {\\\"url\\\":\\\"2\\\",\\\"payload\\\":\\\"{\\\\\\\"number\\\\\\\":2,\\\\\\\"code\\\\\\\":2}\\\",\\\"method\\\":{\\\"tag\\\":\\\"GET\\\"},\\\"headers\\\":[]}\",\"error\":true},\"code\":400},\"tag\":\"LeftEx\"},\"jsonRequest\":{\"url\":\"2\",\"payload\":\"{\\\"number\\\":2,\\\"code\\\":2}\",\"method\":{\"tag\":\"GET\"},\"headers\":[]}},\"tag\":\"CallAPIGenericEntry\"}"
callAPIScript' :: BackendFlow Unit Unit (Tuple (APIResult SomeResponse) (APIResult SomeResponse))
callAPIScript' = do
eRes1 <- callAPI emptyHeaders $ SomeRequest { code: 1, number: 3.0 }
eRes2 <- callAPI emptyHeaders $ SomeRequest { code: 2, number: 4.0 }
pure $ Tuple eRes1 eRes2
callAPIGenericScript' :: BackendFlow Unit Unit (Tuple (APIResult SomeGenericResponse) (APIResult SomeGenericResponse))
callAPIGenericScript' = do
eRes1 <- callAPIGeneric emptyHeaders $ SomeRequest { code: 1, number: 3.0 }
eRes2 <- callAPIGeneric emptyHeaders $ SomeRequest { code: 2, number: 4.0 }
pure $ Tuple eRes1 eRes2
logAndCallAPIScript :: BackendFlow Unit Unit (Tuple (APIResult SomeResponse) (APIResult SomeResponse))
logAndCallAPIScript = do
logScript
callAPIScript
logAndCallAPIScript' :: BackendFlow Unit Unit (Tuple (APIResult SomeResponse) (APIResult SomeResponse))
logAndCallAPIScript' = do
logScript'
callAPIScript'
logAndCallAPIGenericScript :: BackendFlow Unit Unit (Tuple (APIResult SomeGenericResponse) (APIResult SomeGenericResponse))
logAndCallAPIGenericScript = do
logScript
callAPIGenericScript
logAndCallAPIGenericScript' :: BackendFlow Unit Unit (Tuple (APIResult SomeGenericResponse) (APIResult SomeGenericResponse))
logAndCallAPIGenericScript' = do
logScript'
callAPIGenericScript'
runSysCmdScript :: BackendFlow Unit Unit String
runSysCmdScript = runSysCmd "echo 'ABC'"
runSysCmdScript' :: BackendFlow Unit Unit String
runSysCmdScript' = runSysCmd "echo 'DEF'"
doAffScript :: BackendFlow Unit Unit String
doAffScript = doAffRR (pure "This is result.")
doAffScript' :: BackendFlow Unit Unit String
doAffScript' = doAffRR (pure "This is result 2.")
testDB :: String
testDB = "TestDB"
dbScript0 :: BackendFlow Unit Unit SqlConn
dbScript0 = getDBConn testDB
skipScript1 :: BackendFlow Unit Unit String
skipScript1 = do
_ <- runSysCmd "echo 'abcde'"
_ <- doAffRR (pure "doAffRR result")
runSysCmd "echo 'fghij'"
skipScript2 :: BackendFlow Unit Unit String
skipScript2 = do
_ <- runSysCmd "echo 'abcde'"
runSysCmd "echo 'fghij'"
forkFlowScript :: BackendFlow Unit Unit String
forkFlowScript = do
_ <- doAffRR (pure "doAff from main flow")
_ <- forkFlow' "Child 1" $ do
_ <- doAffRR (pure "doAff 1 from forkFlow")
_ <- doAffRR (pure "doAff 2 from forkFlow")
_ <- runSysCmd "sleep 0.5s"
_ <- doAffRR (pure "doAff 3 from forkFlow")
_ <- doAffRR (pure "doAff 4 from forkFlow")
_ <- runSysCmd "sleep 1s"
_ <- doAffRR (pure "doAff 5 from forkFlow")
doAffRR (pure "doAff 6 from forkFlow")
_ <- doAffRR (pure "doAff from main flow")
_ <- runSysCmd "echo 'mainflow 1'"
_ <- runSysCmd "echo 'mainflow 2'"
_ <- forkFlow' "Child 2" $ do
_ <- doAffRR (pure "doAff 1 from forkFlow 2")
_ <- forkFlow' "Child 2 Child 1" $ do
_ <- doAffRR (pure "doAff 1 from forkFlow Child 2 Child 1")
_ <- doAffRR (pure "doAff 2 from forkFlow Child 2 Child 1")
doAffRR (pure "doAff 3 from forkFlow Child 2 Child 1")
_ <- doAffRR (pure "doAff 2 from forkFlow 2")
_ <- runSysCmd "sleep 0.5s"
_ <- doAffRR (pure "doAff 3 from forkFlow 2")
_ <- doAffRR (pure "doAff 4 from forkFlow 2")
_ <- runSysCmd "sleep 1s"
_ <- doAffRR (pure "doAff 5 from forkFlow 2")
doAffRR (pure "doAff 6 from forkFlow 2")
_ <- runSysCmd "sleep 0.5s"
_ <- runSysCmd "echo 'mainflow 3'"
_ <- runSysCmd "echo 'mainflow 4'"
_ <- runSysCmd "sleep 0.5s"
_ <- runSysCmd "echo 'mainflow 5'"
runSysCmd "echo 'mainflow 6'"
getOptionScript :: BackendFlow Unit Unit (Tuple (Maybe Gateway) (Maybe Gateway))
getOptionScript = do
gwa <- getOption $ GatewayKey "explicitGWA"
gwb <- getOption $ GatewayKey "explicitGWB"
pure $ Tuple gwa gwb
setOptionScript :: BackendFlow Unit Unit (Maybe Gateway)
setOptionScript = do
setOption (GatewayKey "explicitGWC") GwC
getOption $ GatewayKey "explicitGWC"
mkBackendRuntime :: AVar (StrMap.StrMap String) -> KVDBRuntime -> RunningMode -> BackendRuntime
mkBackendRuntime options kvdbRuntime mode = BackendRuntime
{ apiRunner
, connections : StrMap.empty
, logRunner
, affRunner
, kvdbRuntime
, mode
, options
}
createKVDBRuntime :: forall t184.
Aff
( avar :: AVAR
| t184
)
KVDBRuntime
createKVDBRuntime = do
multiesVar' <- makeVar StrMap.empty
pure $ KVDBRuntime
{ multiesVar : multiesVar'
}
createRegularBackendRuntime :: forall t274.
Aff
( avar :: AVAR
| t274
)
BackendRuntime
createRegularBackendRuntime = do
kvdbRuntime <- createKVDBRuntime
options <-mkOptions
pure $ mkBackendRuntime options kvdbRuntime RegularMode
createRecordingBackendRuntimeForked
:: forall eff
. Aff ( avar :: AVAR | eff )
{ brt :: BackendRuntime
, recordingVar :: AVar RecordingEntries
, forkedRecordingsVar :: AVar (StrMap.StrMap (AVar RecordingEntries))
}
createRecordingBackendRuntimeForked = do
kvdbRuntime <- createKVDBRuntime
recordingVar <- makeVar []
options <- mkOptions
forkedRecordingsVar <- makeVar StrMap.empty
let brt = mkBackendRuntime options kvdbRuntime $ RecordingMode
{ flowGUID : ""
, recordingVar
, forkedRecordingsVar
, disableEntries : []
}
pure { brt, recordingVar, forkedRecordingsVar }
createRecordingBackendRuntime
:: forall eff
. Aff ( avar :: AVAR | eff ) (Tuple BackendRuntime (AVar (Array RecordingEntry)))
createRecordingBackendRuntime = do
kvdbRuntime <- createKVDBRuntime
recordingVar <- makeVar []
forkedRecordingsVar <- makeVar StrMap.empty
options <- mkOptions
let brt = mkBackendRuntime options kvdbRuntime $ RecordingMode
{ flowGUID : ""
, recordingVar
, forkedRecordingsVar
, disableEntries : []
}
pure $ Tuple brt recordingVar
createRecordingBackendRuntimeWithMode entries = do
kvdbRuntime <- createKVDBRuntime
recordingVar <- makeVar []
forkedRecordingsVar <- makeVar StrMap.empty
options <- mkOptions
let brt = mkBackendRuntime options kvdbRuntime $ RecordingMode
{ flowGUID : ""
, recordingVar
, forkedRecordingsVar
, disableEntries : entries
}
pure $ Tuple brt recordingVar
createRecordingBackendRuntimeWithEntryMode entryMode = do
kvdbRuntime <- createKVDBRuntime
recordingVar <- makeVar entryMode
forkedRecordingsVar <- makeVar StrMap.empty
options <- mkOptions
let brt = mkBackendRuntime options kvdbRuntime $ RecordingMode
{ flowGUID : ""
, forkedRecordingsVar
, recordingVar
, disableEntries : []
}
pure $ Tuple brt recordingVar
runTests :: Spec _ Unit
runTests = do
describe "Options test" do
it "getOption test" $ do
brt <- createRegularBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt getOptionScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right (Tuple (Tuple gwa gwb) unit) -> do
gwa `shouldEqual` (Just GwA)
gwb `shouldEqual` (Just GwB)
it "setOption test" $ do
brt <- createRegularBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt setOptionScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right (Tuple gwc unit) -> gwc `shouldEqual` Just GwC
describe "Regular mode tests" do
it "Log regular mode test" $ do
brt <- createRegularBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right _ -> pure unit
it "CallAPI regular mode test" $ do
brt <- createRegularBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt callAPIScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right (Tuple (Tuple eRes1 eRes2) _) -> do
isRight eRes1 `shouldEqual` true -- TODO: check particular results
isRight eRes2 `shouldEqual` false -- TODO: check particular results
it "CallAPIGeneric regular mode test" $ do
brt <- createRegularBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt callAPIGenericScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right (Tuple (Tuple eRes1 eRes2) _) -> do
isRight eRes1 `shouldEqual` true -- TODO: check particular results
isRight eRes2 `shouldEqual` false -- TODO: check particular results
describe "Recording/replaying mode tests" do
it "Record test" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right _ -> do
recording <- readVar recordingVar
length recording `shouldEqual` 4
index recording 0 `shouldEqual` (Just $ RecordingEntry 0 Normal "LogEntry" log1 )
index recording 1 `shouldEqual` (Just $ RecordingEntry 1 Normal "LogEntry" log2 )
index recording 2 `shouldEqual` (Just (RecordingEntry 2 Normal "CallAPIEntry" capi1 ))
index recording 3 `shouldEqual` (Just (RecordingEntry 3 Normal "CallAPIEntry" capi2 ))
it "Record / replay test: log and callAPI success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIScript) unit) unit)
isRight eResult `shouldEqual` true
stepVar <- makeVar 0
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime logAndCallAPIScript) unit) unit)
curStep <- readVar stepVar
isRight eResult2 `shouldEqual` true
case [eResult, eResult2] of
[Right res, Right res2] -> res `shouldEqual` res2
_ -> fail "Not equal."
curStep `shouldEqual` 4
mbErr <- readVar errorVar
mbErr `shouldEqual` Nothing
it "Record / replay test: index out of range" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIScript) unit) unit)
isRight eResult `shouldEqual` true
stepVar <- makeVar 10
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime logAndCallAPIScript) unit) unit)
curStep <- readVar stepVar
pbError <- readVar errorVar
isRight eResult2 `shouldEqual` false
pbError `shouldEqual` (Just (PlaybackError
{ errorMessage: "\n Flow step: tag: logging1, message: \"try1\""
, errorType: UnexpectedRecordingEnd
}))
curStep `shouldEqual` 10
it "Record / replay test: started from the middle" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIScript) unit) unit)
isRight eResult `shouldEqual` true
stepVar <- makeVar 2
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime logAndCallAPIScript) unit) unit)
curStep <- readVar stepVar
pbError <- readVar errorVar
isRight eResult2 `shouldEqual` false
pbError `shouldEqual` (Just (PlaybackError { errorMessage: "\n Flow step: tag: logging1, message: \"try1\"\n Recording entry: (RecordingEntry 2 Normal \"CallAPIEntry\" \"{\\\"contents\\\":{\\\"jsonResult\\\":{\\\"contents\\\":{\\\"string\\\":\\\"Hello there!\\\",\\\"code\\\":1},\\\"tag\\\":\\\"RightEx\\\"},\\\"jsonRequest\\\":{\\\"url\\\":\\\"1\\\",\\\"payload\\\":\\\"{\\\\\\\"number\\\\\\\":1,\\\\\\\"code\\\\\\\":1}\\\",\\\"method\\\":{\\\"tag\\\":\\\"GET\\\"},\\\"headers\\\":[]}},\\\"tag\\\":\\\"CallAPIEntry\\\"}\")", errorType: UnknownRRItem }))
curStep `shouldEqual` 3
it "Record test" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIGenericScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right _ -> do
recording <- readVar recordingVar
length recording `shouldEqual` 4
index recording 0 `shouldEqual` (Just $ RecordingEntry 0 Normal "LogEntry" log1 )
index recording 1 `shouldEqual` (Just $ RecordingEntry 1 Normal "LogEntry" log2 )
index recording 2 `shouldEqual` (Just (RecordingEntry 2 Normal "CallAPIGenericEntry" capig1 ))
index recording 3 `shouldEqual` (Just (RecordingEntry 3 Normal "CallAPIGenericEntry" capig2 ))
it "Record / replay test: log and callAPI success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIGenericScript) unit) unit)
isRight eResult `shouldEqual` true
stepVar <- makeVar 0
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime logAndCallAPIGenericScript) unit) unit)
curStep <- readVar stepVar
isRight eResult2 `shouldEqual` true
case [eResult, eResult2] of
[Right res, Right res2] -> res `shouldEqual` res2
_ -> fail "Not equal."
curStep `shouldEqual` 4
mbErr <- readVar errorVar
mbErr `shouldEqual` Nothing
it "Record / replay test: index out of range" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIGenericScript) unit) unit)
isRight eResult `shouldEqual` true
stepVar <- makeVar 10
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime logAndCallAPIGenericScript) unit) unit)
curStep <- readVar stepVar
pbError <- readVar errorVar
isRight eResult2 `shouldEqual` false
pbError `shouldEqual` (Just (PlaybackError
{ errorMessage: "\n Flow step: tag: logging1, message: \"try1\""
, errorType: UnexpectedRecordingEnd
}))
curStep `shouldEqual` 10
it "Record / replay test: started from the middle" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIGenericScript) unit) unit)
isRight eResult `shouldEqual` true
stepVar <- makeVar 2
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime logAndCallAPIGenericScript) unit) unit)
curStep <- readVar stepVar
pbError <- readVar errorVar
isRight eResult2 `shouldEqual` false
pbError `shouldEqual` (Just (PlaybackError { errorMessage: "\n Flow step: tag: logging1, message: \"try1\"\n Recording entry: (RecordingEntry 2 Normal \"CallAPIGenericEntry\" \"{\\\"contents\\\":{\\\"jsonResult\\\":{\\\"contents\\\":{\\\"string\\\":\\\"Hello there!\\\",\\\"code\\\":1},\\\"tag\\\":\\\"RightEx\\\"},\\\"jsonRequest\\\":{\\\"url\\\":\\\"1\\\",\\\"payload\\\":\\\"{\\\\\\\"number\\\\\\\":1,\\\\\\\"code\\\\\\\":1}\\\",\\\"method\\\":{\\\"tag\\\":\\\"GET\\\"},\\\"headers\\\":[]}},\\\"tag\\\":\\\"CallAPIGenericEntry\\\"}\")", errorType: UnknownRRItem }))
curStep `shouldEqual` 3
it "Record / replay test: runSysCmd success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt runSysCmdScript) unit) unit)
case eResult of
Right (Tuple n unit) -> n `shouldEqual` "ABC\n"
_ -> fail $ show eResult
stepVar <- makeVar 0
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime runSysCmdScript) unit) unit)
curStep <- readVar stepVar
case eResult2 of
Right (Tuple n unit) -> n `shouldEqual` "ABC\n"
Left err -> fail $ show err
curStep `shouldEqual` 1
mbErr <- readVar errorVar
mbErr `shouldEqual` Nothing
it "Record / replay test: throwException success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt $ throwException "This is error!") unit) unit)
case eResult of
Left (Tuple err _) -> message err `shouldEqual` "This is error!"
_ -> fail "Unexpected success."
stepVar <- makeVar 0
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime $ throwException "This is error!") unit) unit)
curStep <- readVar stepVar
case eResult2 of
Left (Tuple err _) -> message err `shouldEqual` "This is error!"
_ -> fail "Unexpected success."
curStep `shouldEqual` 1
mbErr <- readVar errorVar
mbErr `shouldEqual` Nothing
it "Record / replay test: doAff success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt doAffScript) unit) unit)
case eResult of
Right (Tuple n unit) -> n `shouldEqual` "This is result."
_ -> fail $ show eResult
stepVar <- makeVar 0
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime doAffScript) unit) unit)
curStep <- readVar stepVar
case eResult2 of
Right (Tuple n unit) -> n `shouldEqual` "This is result."
Left err -> fail $ show err
curStep `shouldEqual` 1
mbErr <- readVar errorVar
mbErr `shouldEqual` Nothing
it "Record / replay test: forkFlow no forked entries" $ do
{brt, recordingVar, forkedRecordingsVar} <- createRecordingBackendRuntimeForked
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt forkFlowScript) unit) unit)
case eResult of
Right (Tuple n unit) -> n `shouldEqual` "mainflow 6\n"
_ -> fail $ show eResult
stepVar <- makeVar 0
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedRecordings' <- readVar forkedRecordingsVar
let kvFunc (Tuple k recVar) = Tuple k <$> readVar recVar
let (kvs :: Array (Tuple String (AVar RecordingEntries))) = StrMap.toUnfoldable forkedRecordings'
forkedRecordings'' <- traverse kvFunc kvs
let forkedRecordings = StrMap.fromFoldable forkedRecordings''
length recording `shouldEqual` 16
StrMap.size forkedRecordings `shouldEqual` 3
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime forkFlowScript) unit) unit)
curStep <- readVar stepVar
case eResult2 of
Right (Tuple n unit) -> n `shouldEqual` "mainflow 6\n"
Left err -> fail $ show err
curStep `shouldEqual` 16
mbErr <- readVar errorVar
mbErr `shouldEqual` Nothing
forkedErrs <- readVar forkedFlowErrorsVar
StrMap.size forkedErrs `shouldEqual` 2
it "Record / replay test: forkFlow success" $ do
{brt, recordingVar, forkedRecordingsVar} <- createRecordingBackendRuntimeForked
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt forkFlowScript) unit) unit)
case eResult of
Right (Tuple n unit) -> n `shouldEqual` "mainflow 6\n"
_ -> fail $ show eResult
stepVar <- makeVar 0
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedRecordings' <- readVar forkedRecordingsVar
let kvFunc (Tuple k recVar) = Tuple k <$> readVar recVar
let (kvs :: Array (Tuple String (AVar RecordingEntries))) = StrMap.toUnfoldable forkedRecordings'
forkedRecordings'' <- traverse kvFunc kvs
let forkedRecordings = StrMap.fromFoldable forkedRecordings''
length recording `shouldEqual` 16
StrMap.size forkedRecordings `shouldEqual` 3
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : forkedRecordings
, forkedFlowErrorsVar
, recording
, disableVerify : []
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options
}
eResult2 <- liftAff $ runExceptT (runStateT (runReaderT (runBackend replayingBackendRuntime forkFlowScript) unit) unit)
curStep <- readVar stepVar
case eResult2 of
Right (Tuple n unit) -> n `shouldEqual` "mainflow 6\n"
Left err -> fail $ show err
curStep `shouldEqual` 16
mbErr <- readVar errorVar
mbErr `shouldEqual` Nothing
forkedErrs <- readVar forkedFlowErrorsVar
StrMap.size forkedErrs `shouldEqual` 0
it "Record / replay test: getDBConn success" $ do
Tuple (BackendRuntime rt') recordingVar <- createRecordingBackendRuntime
let conns = StrMap.singleton testDB $ SqlConn $ MockedSql $ MockedSqlConn testDB
let rt = BackendRuntime $ rt' { connections = conns }
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend rt dbScript0) unit) unit)
case eResult of
Right (Tuple (MockedSql (MockedSqlConn dbName)) unit) -> dbName `shouldEqual` testDB
Left err -> fail $ show err
_ -> fail "Unknown result"
describe "Recording test with Global Config Mode" do
it "Record Test : LogEntry success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntimeWithMode ["LogEntry"]
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right _ -> do
recording <- readVar recordingVar
length recording `shouldEqual` 2
index recording 0 `shouldEqual` (Just (RecordingEntry 0 Normal "CallAPIEntry" capi1))
index recording 1 `shouldEqual` (Just (RecordingEntry 1 Normal "CallAPIEntry" capi2 ))
it "Record Test : CallAPIEntry success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntimeWithMode ["CallAPIEntry"]
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logAndCallAPIScript) unit) unit)
case eResult of
Left err -> fail $ show err
Right _ -> do
recording <- readVar recordingVar
length recording `shouldEqual` 2
index recording 0 `shouldEqual` (Just $ RecordingEntry 0 Normal "LogEntry" log1 )
index recording 1 `shouldEqual` (Just $ RecordingEntry 1 Normal "LogEntry" log2 )
it "Record Test: runSysCmd success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntimeWithMode ["RunSysCmdEntry"]
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt runSysCmdScript) unit) unit)
case eResult of
Right (Tuple n unit) -> n `shouldEqual` "ABC\n"
_ -> fail "Test failed."
it "Record test: doAff success" $ do
Tuple brt recordingVar <- createRecordingBackendRuntimeWithMode ["DoAffEntry"]
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt doAffScript) unit) unit)
case eResult of
Right (Tuple n unit) -> n `shouldEqual` "This is result."
_ -> fail "Test failed."
describe "Replaying test with disable Verify Global Config Mode" do
it "Replay test : LogEntry" $ do
Tuple brt recordingVar <- createRecordingBackendRuntime
eResult <- liftAff $ runExceptT (runStateT (runReaderT (runBackend brt logScript) unit) unit)
isRight eResult `shouldEqual` true
stepVar <- makeVar 0
errorVar <- makeVar Nothing
recording <- readVar recordingVar
kvdbRuntime <- createKVDBRuntime
forkedFlowErrorsVar <- makeVar StrMap.empty
options <- mkOptions
let replayingBackendRuntime = BackendRuntime
{ apiRunner : failingApiRunner
, connections : StrMap.empty
, logRunner : failingLogRunner
, affRunner : failingAffRunner
, kvdbRuntime
, mode : ReplayingMode
{ flowGUID : ""
, forkedFlowRecordings : StrMap.empty
, forkedFlowErrorsVar
, recording
, disableVerify : ["LogEntry"]
, disableMocking : []
, skipEntries : []
, entriesFiltered : false
, stepVar
, errorVar
}
, options