mirror of
https://github.com/haskell-nix/hnix-store.git
synced 2024-09-11 18:05:56 +03:00
tests: custom Arbitrary Metadata instance with forced SHA256 metadataNarHash, w/o (Just0) metadataNarBytes
This commit is contained in:
parent
a8077c5031
commit
2cd4c32b84
@ -178,7 +178,6 @@ test-suite remote
|
||||
, hnix-store-tests
|
||||
, cereal
|
||||
, crypton
|
||||
, dependent-sum > 0.7
|
||||
, some > 1.0.5 && < 2
|
||||
, text
|
||||
, time
|
||||
|
@ -3,7 +3,6 @@
|
||||
module NixSerializerSpec (spec) where
|
||||
|
||||
import Crypto.Hash (MD5, SHA1, SHA256, SHA512)
|
||||
import Data.Dependent.Sum (DSum((:=>)))
|
||||
import Data.Some (Some(Some))
|
||||
import Data.Time (UTCTime)
|
||||
import Data.Word (Word64)
|
||||
@ -11,12 +10,9 @@ import Test.Hspec (Expectation, Spec, describe, it, parallel, shouldBe)
|
||||
import Test.Hspec.QuickCheck (prop)
|
||||
import Test.QuickCheck (Gen, arbitrary, forAll, suchThat)
|
||||
|
||||
import qualified System.Nix.Hash
|
||||
|
||||
import System.Nix.Arbitrary ()
|
||||
import System.Nix.Derivation (Derivation(inputDrvs))
|
||||
import System.Nix.StorePath (StoreDir)
|
||||
import System.Nix.StorePath.Metadata (Metadata(..))
|
||||
import System.Nix.Store.Remote.Arbitrary ()
|
||||
import System.Nix.Store.Remote.Serializer
|
||||
import System.Nix.Store.Remote.Types.Logger (Logger(..))
|
||||
@ -81,14 +77,8 @@ spec = parallel $ do
|
||||
prop "StorePathName" $
|
||||
roundtripS storePathName
|
||||
|
||||
let narHashIsSHA256 Metadata{..} =
|
||||
case metadataNarHash of
|
||||
(System.Nix.Hash.HashAlgo_SHA256 :=> _) -> True
|
||||
_ -> False
|
||||
|
||||
prop "Metadata (StorePath)"
|
||||
$ \sd -> forAll (arbitrary `suchThat` (\m -> narHashIsSHA256 m && metadataNarBytes m /= Just 0))
|
||||
$ roundtripSReader @StoreDir pathMetadata sd
|
||||
prop "Metadata (StorePath)" $
|
||||
roundtripSReader @StoreDir pathMetadata
|
||||
|
||||
prop "Some HashAlgo" $
|
||||
roundtripS someHashAlgo
|
||||
|
@ -4,6 +4,7 @@
|
||||
{-# OPTIONS_GHC -Wno-orphans #-}
|
||||
module System.Nix.Arbitrary.StorePath.Metadata where
|
||||
|
||||
import Data.Dependent.Sum (DSum((:=>)))
|
||||
import Data.HashSet.Arbitrary ()
|
||||
import System.Nix.Arbitrary.ContentAddress ()
|
||||
import System.Nix.Arbitrary.Hash ()
|
||||
@ -11,14 +12,24 @@ import System.Nix.Arbitrary.Signature ()
|
||||
import System.Nix.Arbitrary.StorePath ()
|
||||
import System.Nix.Arbitrary.UTCTime ()
|
||||
import System.Nix.StorePath (StorePath)
|
||||
import System.Nix.StorePath.Metadata (Metadata, StorePathTrust)
|
||||
import System.Nix.StorePath.Metadata (Metadata(..), StorePathTrust)
|
||||
|
||||
import Test.QuickCheck (Arbitrary(..))
|
||||
import qualified System.Nix.Hash
|
||||
|
||||
import Test.QuickCheck (Arbitrary(..), suchThat)
|
||||
import Test.QuickCheck.Arbitrary.Generic (GenericArbitrary(..))
|
||||
|
||||
deriving via GenericArbitrary StorePathTrust
|
||||
instance Arbitrary StorePathTrust
|
||||
|
||||
deriving via GenericArbitrary (Metadata StorePath)
|
||||
instance Arbitrary (Metadata StorePath)
|
||||
|
||||
instance Arbitrary (Metadata StorePath) where
|
||||
arbitrary = do
|
||||
metadataDeriverPath <- arbitrary
|
||||
metadataNarHash <- (System.Nix.Hash.HashAlgo_SHA256 :=>) <$> arbitrary
|
||||
metadataReferences <- arbitrary
|
||||
metadataRegistrationTime <- arbitrary
|
||||
metadataNarBytes <- arbitrary `suchThat` (/= Just 0)
|
||||
metadataTrust <- arbitrary
|
||||
metadataSigs <- arbitrary
|
||||
metadataContentAddress <- arbitrary
|
||||
pure Metadata{..}
|
||||
|
Loading…
Reference in New Issue
Block a user