mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-09-11 18:05:56 +03:00
remote: move enum tests to EnumSpec
This commit is contained in:
parent
428a61a538
commit
7bdbab9c53
@ -170,6 +170,7 @@ test-suite remote
|
||||
ghc-options: -Wall -threaded -rtsopts "-with-rtsopts -N"
|
||||
other-modules:
|
||||
Data.SerializerSpec
|
||||
EnumSpec
|
||||
NixSerializerSpec
|
||||
SerializeSpec
|
||||
build-tool-depends:
|
||||
@ -179,6 +180,7 @@ test-suite remote
|
||||
, hnix-store-core
|
||||
, hnix-store-remote
|
||||
, hnix-store-tests
|
||||
, bytestring
|
||||
, cereal
|
||||
, crypton
|
||||
, some > 1.0.5 && < 2
|
||||
|
@ -68,6 +68,7 @@ module System.Nix.Store.Remote.Serializer
|
||||
, LoggerSError(..)
|
||||
, activityID
|
||||
, maybeActivity
|
||||
, activity
|
||||
, activityResult
|
||||
, field
|
||||
, trace
|
||||
@ -886,12 +887,12 @@ maybeActivity = Serializer
|
||||
Nothing -> putS (int @Int) 0
|
||||
Just act -> putS activity act
|
||||
}
|
||||
where
|
||||
activity :: NixSerializer r LoggerSError Activity
|
||||
activity = Serializer
|
||||
{ getS = mapPrimE $ getS int >>= toEnumCheckBoundsM . (+(-100))
|
||||
, putS = putS int . (+100) . fromEnum
|
||||
}
|
||||
|
||||
activity :: NixSerializer r LoggerSError Activity
|
||||
activity = Serializer
|
||||
{ getS = mapPrimE $ getS int >>= toEnumCheckBoundsM . (+(-100))
|
||||
, putS = putS int . (+100) . fromEnum
|
||||
}
|
||||
|
||||
activityID :: NixSerializer r LoggerSError ActivityID
|
||||
activityID = mapIsoSerializer ActivityID unActivityID int
|
||||
|
136
hnix-store-remote/tests/EnumSpec.hs
Normal file
136
hnix-store-remote/tests/EnumSpec.hs
Normal file
@ -0,0 +1,136 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module EnumSpec (spec) where
|
||||
|
||||
import Test.Hspec (SpecWith, Spec, describe, it, shouldBe)
|
||||
|
||||
import Data.ByteString (ByteString)
|
||||
import Data.Word (Word64)
|
||||
import System.Nix.Build (BuildMode(..), BuildStatus(..))
|
||||
import System.Nix.Store.Remote.Serializer
|
||||
( activity
|
||||
, activityResult
|
||||
, enum
|
||||
, int
|
||||
, loggerOpCode
|
||||
, runP
|
||||
, LoggerSError
|
||||
, NixSerializer
|
||||
, SError
|
||||
)
|
||||
import System.Nix.Store.Remote.Types
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
let
|
||||
itE
|
||||
:: ( Enum a
|
||||
, Show a
|
||||
)
|
||||
=> String
|
||||
-> a
|
||||
-> Word64
|
||||
-> SpecWith ()
|
||||
itE name constr value =
|
||||
it name
|
||||
$ ((runP enum () constr) :: Either SError ByteString)
|
||||
`shouldBe`
|
||||
(runP (int @Word64) () value)
|
||||
|
||||
itE'
|
||||
:: Show a
|
||||
=> NixSerializer () LoggerSError a
|
||||
-> String
|
||||
-> a
|
||||
-> Word64
|
||||
-> SpecWith ()
|
||||
itE' s name constr value =
|
||||
it name
|
||||
$ ((runP s () constr) :: Either LoggerSError ByteString)
|
||||
`shouldBe`
|
||||
(runP (int @Word64) () (value))
|
||||
|
||||
describe "Enums" $ do
|
||||
describe "BuildMode enum order matches Nix" $ do
|
||||
itE "Normal" BuildMode_Normal 0
|
||||
itE "Repair" BuildMode_Repair 1
|
||||
itE "Check" BuildMode_Check 2
|
||||
|
||||
describe "BuildStatus enum order matches Nix" $ do
|
||||
itE "Built" BuildStatus_Built 0
|
||||
itE "Substituted" BuildStatus_Substituted 1
|
||||
itE "AlreadyValid" BuildStatus_AlreadyValid 2
|
||||
itE "PermanentFailure" BuildStatus_PermanentFailure 3
|
||||
itE "InputRejected" BuildStatus_InputRejected 4
|
||||
itE "OutputRejected" BuildStatus_OutputRejected 5
|
||||
itE "TransientFailure" BuildStatus_TransientFailure 6
|
||||
itE "CachedFailure" BuildStatus_CachedFailure 7
|
||||
itE "TimedOut" BuildStatus_TimedOut 8
|
||||
itE "MiscFailure" BuildStatus_MiscFailure 9
|
||||
itE "DependencyFailed" BuildStatus_DependencyFailed 10
|
||||
itE "LogLimitExceeded" BuildStatus_LogLimitExceeded 11
|
||||
itE "NotDeterministic" BuildStatus_NotDeterministic 12
|
||||
itE "ResolvesToAlreadyValid" BuildStatus_ResolvesToAlreadyValid 13
|
||||
itE "NoSubstituters" BuildStatus_NoSubstituters 14
|
||||
|
||||
describe "GCAction enum order matches Nix" $ do
|
||||
itE "ReturnLive" GCAction_ReturnLive 0
|
||||
itE "ReturnDead" GCAction_ReturnDead 1
|
||||
itE "DeleteDead" GCAction_DeleteDead 2
|
||||
itE "DeleteSpecific" GCAction_DeleteSpecific 3
|
||||
|
||||
describe "Logger" $ do
|
||||
let itA = itE' activity
|
||||
describe "Activity enum order matches Nix" $ do
|
||||
itA "CopyPath" Activity_CopyPath 100
|
||||
itA "FileTransfer" Activity_FileTransfer 101
|
||||
itA "Realise" Activity_Realise 102
|
||||
itA "CopyPaths" Activity_CopyPaths 103
|
||||
itA "Builds" Activity_Builds 104
|
||||
itA "Build" Activity_Build 105
|
||||
itA "OptimiseStore" Activity_OptimiseStore 106
|
||||
itA "VerifyPaths" Activity_VerifyPaths 107
|
||||
itA "Substitute" Activity_Substitute 108
|
||||
itA "QueryPathInfo" Activity_QueryPathInfo 109
|
||||
itA "PostBuildHook" Activity_PostBuildHook 110
|
||||
itA "BuildWaiting" Activity_BuildWaiting 111
|
||||
|
||||
let itR = itE' activityResult
|
||||
describe "ActivityResult enum order matches Nix" $ do
|
||||
itR "FileLinked" ActivityResult_FileLinked 100
|
||||
itR "BuildLogLine" ActivityResult_BuildLogLine 101
|
||||
itR "UnstrustedPath" ActivityResult_UnstrustedPath 102
|
||||
itR "CorruptedPath" ActivityResult_CorruptedPath 103
|
||||
itR "SetPhase" ActivityResult_SetPhase 104
|
||||
itR "Progress" ActivityResult_Progress 105
|
||||
itR "SetExpected" ActivityResult_SetExpected 106
|
||||
itR "PostBuildLogLine" ActivityResult_PostBuildLogLine 107
|
||||
|
||||
|
||||
let itL = itE' loggerOpCode
|
||||
describe "LoggerOpCode matches Nix" $ do
|
||||
itL "Next" LoggerOpCode_Next 0x6f6c6d67
|
||||
itL "Read" LoggerOpCode_Read 0x64617461
|
||||
itL "Write" LoggerOpCode_Write 0x64617416
|
||||
itL "Last" LoggerOpCode_Last 0x616c7473
|
||||
itL "Error" LoggerOpCode_Error 0x63787470
|
||||
itL "StartActivity" LoggerOpCode_StartActivity 0x53545254
|
||||
itL "StopActivity" LoggerOpCode_StopActivity 0x53544f50
|
||||
itL "Result" LoggerOpCode_Result 0x52534c54
|
||||
|
||||
describe "Verbosity enum order matches Nix" $ do
|
||||
itE "Error" Verbosity_Error 0
|
||||
itE "Warn" Verbosity_Warn 1
|
||||
itE "Notice" Verbosity_Notice 2
|
||||
itE "Info" Verbosity_Info 3
|
||||
itE "Talkative" Verbosity_Talkative 4
|
||||
itE "Chatty" Verbosity_Chatty 5
|
||||
itE "Debug" Verbosity_Debug 6
|
||||
itE "Vomit" Verbosity_Vomit 7
|
||||
|
||||
describe "WorkerOp enum order matches Nix" $ do
|
||||
itE "IsValidPath" WorkerOp_IsValidPath 1
|
||||
itE "BuildPathsWithResults" WorkerOp_BuildPathsWithResults 46
|
||||
|
||||
|
||||
|
@ -5,8 +5,7 @@ module NixSerializerSpec (spec) where
|
||||
import Crypto.Hash (MD5, SHA1, SHA256, SHA512)
|
||||
import Data.Some (Some(Some))
|
||||
import Data.Time (UTCTime)
|
||||
import Data.Word (Word64)
|
||||
import Test.Hspec (Expectation, Spec, describe, it, parallel, shouldBe)
|
||||
import Test.Hspec (Expectation, Spec, describe, parallel, shouldBe)
|
||||
import Test.Hspec.QuickCheck (prop)
|
||||
import Test.QuickCheck (Gen, arbitrary, forAll, suchThat)
|
||||
|
||||
@ -20,7 +19,6 @@ import System.Nix.Store.Remote.Types.Logger (Logger(..))
|
||||
import System.Nix.Store.Remote.Types.ProtoVersion (HasProtoVersion(..), ProtoVersion(..))
|
||||
import System.Nix.Store.Remote.Types.StoreConfig (TestStoreConfig(..))
|
||||
import System.Nix.Store.Remote.Types.StoreRequest (StoreRequest(..))
|
||||
import System.Nix.Store.Remote.Types.WorkerOp (WorkerOp(..))
|
||||
|
||||
-- | Test for roundtrip using @NixSerializer@
|
||||
roundtripSReader
|
||||
@ -138,18 +136,6 @@ spec = parallel $ do
|
||||
forAll (arbitrary `suchThat` errorInfoIf (protoVersion_minor pv >= 26))
|
||||
$ roundtripSReader logger pv
|
||||
|
||||
describe "Enums" $ do
|
||||
let it' name constr value =
|
||||
it name
|
||||
$ (runP enum () constr)
|
||||
`shouldBe`
|
||||
(runP (int @Word64) () value)
|
||||
|
||||
describe "WorkerOp enum order matches Nix" $ do
|
||||
it' "IsValidPath" WorkerOp_IsValidPath 1
|
||||
it' "BuildPathsWithResults" WorkerOp_BuildPathsWithResults 46
|
||||
|
||||
|
||||
describe "Handshake" $ do
|
||||
prop "WorkerMagic" $ roundtripS workerMagic
|
||||
prop "TrustedFlag" $ roundtripS trustedFlag
|
||||
|
@ -6,7 +6,7 @@ import Data.Serialize (Serialize(..))
|
||||
import Data.Serialize.Get (Get, runGet)
|
||||
import Data.Serialize.Put (Putter, runPut)
|
||||
import Data.Text (Text)
|
||||
import Test.Hspec (Expectation, Spec, describe, it, parallel, shouldBe)
|
||||
import Test.Hspec (Expectation, Spec, describe, parallel)
|
||||
import Test.Hspec.QuickCheck (prop)
|
||||
import Test.Hspec.Nix (roundtrips)
|
||||
|
||||
@ -95,78 +95,3 @@ spec = parallel $ do
|
||||
prop "ErrorInfo" $ roundtripS @ErrorInfo
|
||||
prop "LoggerOpCode" $ roundtripS @LoggerOpCode
|
||||
prop "Verbosity" $ roundtripS @Verbosity
|
||||
|
||||
describe "Enums" $ do
|
||||
let it' name constr value = it name $ runPut (put constr) `shouldBe` runPut (putInt @Int value)
|
||||
describe "BuildMode enum order matches Nix" $ do
|
||||
it' "Normal" BuildMode_Normal 0
|
||||
it' "Repair" BuildMode_Repair 1
|
||||
it' "Check" BuildMode_Check 2
|
||||
|
||||
describe "BuildStatus enum order matches Nix" $ do
|
||||
it' "Built" BuildStatus_Built 0
|
||||
it' "Substituted" BuildStatus_Substituted 1
|
||||
it' "AlreadyValid" BuildStatus_AlreadyValid 2
|
||||
it' "PermanentFailure" BuildStatus_PermanentFailure 3
|
||||
it' "InputRejected" BuildStatus_InputRejected 4
|
||||
it' "OutputRejected" BuildStatus_OutputRejected 5
|
||||
it' "TransientFailure" BuildStatus_TransientFailure 6
|
||||
it' "CachedFailure" BuildStatus_CachedFailure 7
|
||||
it' "TimedOut" BuildStatus_TimedOut 8
|
||||
it' "MiscFailure" BuildStatus_MiscFailure 9
|
||||
it' "DependencyFailed" BuildStatus_DependencyFailed 10
|
||||
it' "LogLimitExceeded" BuildStatus_LogLimitExceeded 11
|
||||
it' "NotDeterministic" BuildStatus_NotDeterministic 12
|
||||
it' "ResolvesToAlreadyValid" BuildStatus_ResolvesToAlreadyValid 13
|
||||
it' "NoSubstituters" BuildStatus_NoSubstituters 14
|
||||
|
||||
describe "GCAction enum order matches Nix" $ do
|
||||
it' "ReturnLive" GCAction_ReturnLive 0
|
||||
it' "ReturnDead" GCAction_ReturnDead 1
|
||||
it' "DeleteDead" GCAction_DeleteDead 2
|
||||
it' "DeleteSpecific" GCAction_DeleteSpecific 3
|
||||
|
||||
describe "Logger" $ do
|
||||
describe "Activity enum order matches Nix" $ do
|
||||
it' "CopyPath" Activity_CopyPath 100
|
||||
it' "FileTransfer" Activity_FileTransfer 101
|
||||
it' "Realise" Activity_Realise 102
|
||||
it' "CopyPaths" Activity_CopyPaths 103
|
||||
it' "Builds" Activity_Builds 104
|
||||
it' "Build" Activity_Build 105
|
||||
it' "OptimiseStore" Activity_OptimiseStore 106
|
||||
it' "VerifyPaths" Activity_VerifyPaths 107
|
||||
it' "Substitute" Activity_Substitute 108
|
||||
it' "QueryPathInfo" Activity_QueryPathInfo 109
|
||||
it' "PostBuildHook" Activity_PostBuildHook 110
|
||||
it' "BuildWaiting" Activity_BuildWaiting 111
|
||||
|
||||
describe "ActivityResult enum order matches Nix" $ do
|
||||
it' "FileLinked" ActivityResult_FileLinked 100
|
||||
it' "BuildLogLine" ActivityResult_BuildLogLine 101
|
||||
it' "UnstrustedPath" ActivityResult_UnstrustedPath 102
|
||||
it' "CorruptedPath" ActivityResult_CorruptedPath 103
|
||||
it' "SetPhase" ActivityResult_SetPhase 104
|
||||
it' "Progress" ActivityResult_Progress 105
|
||||
it' "SetExpected" ActivityResult_SetExpected 106
|
||||
it' "PostBuildLogLine" ActivityResult_PostBuildLogLine 107
|
||||
|
||||
describe "LoggerOpCode matches Nix" $ do
|
||||
it' "Next" LoggerOpCode_Next 0x6f6c6d67
|
||||
it' "Read" LoggerOpCode_Read 0x64617461
|
||||
it' "Write" LoggerOpCode_Write 0x64617416
|
||||
it' "Last" LoggerOpCode_Last 0x616c7473
|
||||
it' "Error" LoggerOpCode_Error 0x63787470
|
||||
it' "StartActivity" LoggerOpCode_StartActivity 0x53545254
|
||||
it' "StopActivity" LoggerOpCode_StopActivity 0x53544f50
|
||||
it' "Result" LoggerOpCode_Result 0x52534c54
|
||||
|
||||
describe "Verbosity enum order matches Nix" $ do
|
||||
it' "Error" Verbosity_Error 0
|
||||
it' "Warn" Verbosity_Warn 1
|
||||
it' "Notice" Verbosity_Notice 2
|
||||
it' "Info" Verbosity_Info 3
|
||||
it' "Talkative" Verbosity_Talkative 4
|
||||
it' "Chatty" Verbosity_Chatty 5
|
||||
it' "Debug" Verbosity_Debug 6
|
||||
it' "Vomit" Verbosity_Vomit 7
|
||||
|
Loading…
Reference in New Issue
Block a user