Skip to content

Commit 6e93a24

Browse files
committed
[cli] refactor: factor out testRunDuration function
1 parent 2f328d0 commit 6e93a24

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

cli/src/User/Agent/Lib.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
module User.Agent.Lib
22
( resolveTestRunId
33
, withState
4+
, testRunDuration
45
) where
56

67
import Control.Applicative (Alternative (..))
78
import Core.Context (WithContext, withMPFS)
8-
import Core.Types.Basic (TokenId)
9+
import Core.Types.Basic (Duration, TokenId)
910
import Core.Types.Fact (Fact (..), keyHash, parseFacts)
1011
import Data.Foldable (find)
1112
import MPFS.API (MPFS (..))
1213
import Text.JSON.Canonical (FromJSON (..), JSValue)
1314
import User.Agent.Types (TestRunId (..))
14-
import User.Types (Phase (..), TestRun, TestRunState)
15+
import User.Types (Phase (..), TestRun, TestRunState (..))
1516

1617
resolveTestRunId
1718
:: forall s m
@@ -42,3 +43,9 @@ withState f v =
4243
state
4344
:: forall s. FromJSON Maybe (TestRunState s) => Maybe (TestRunState s)
4445
state = fromJSON v
46+
47+
testRunDuration :: TestRunState v -> Duration
48+
testRunDuration (Pending d _) = d
49+
testRunDuration (Rejected pending _) = testRunDuration pending
50+
testRunDuration (Accepted pending) = testRunDuration pending
51+
testRunDuration (Finished accepted _ _) = testRunDuration accepted

cli/src/User/Agent/PushTest.hs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ import Text.JSON.Canonical
5252
, ToJSON (..)
5353
, renderCanonicalJSON
5454
)
55-
import User.Agent.Lib (resolveTestRunId, withState)
55+
import User.Agent.Lib (resolveTestRunId, testRunDuration, withState)
5656
import User.Agent.Types
5757
( TestRunId (..)
5858
)
59-
import User.Types (TestRun (..), TestRunState (..))
59+
import User.Types (TestRun (..))
6060

6161
dockerfile :: String
6262
dockerfile =
@@ -195,12 +195,6 @@ collectImagesFromAssets (Directory dirname) = do
195195
let images = nub . sort . filter (not . null) . lines
196196
return $ output <&> images
197197

198-
pickDuration :: TestRunState v -> Duration
199-
pickDuration (Pending d _) = d
200-
pickDuration (Rejected pending _) = pickDuration pending
201-
pickDuration (Accepted pending) = pickDuration pending
202-
pickDuration (Finished accepted _ _) = pickDuration accepted
203-
204198
getTestRun
205199
:: Monad m
206200
=> TokenId
@@ -213,7 +207,7 @@ getTestRun tk testRunId = do
213207
mts <- lift $ resolveTestRunId tk testRunId
214208
Fact tr v <- liftMaybe (Couldn'tResolveTestRunId testRunId) mts
215209
liftMaybe (Couldn'tResolveTestRunId testRunId)
216-
$ withState (\state -> (tr, pickDuration state)) v
210+
$ withState (\state -> (tr, testRunDuration state)) v
217211

218212
data AntithesisAuth = AntithesisAuth
219213
{ username :: String

0 commit comments

Comments
 (0)