git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #150 from bitemyapp/149-qc-failure
0027a45Chris Allen
tests/tests.hs+35−9
@@ -1,5 +1,6 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE DefaultSignatures #-}
3+{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE DeriveGeneric #-}
4{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE FlexibleContexts #-}
5{-# LANGUAGE GeneralizedNewtypeDeriving #-}
6{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -143,8 +144,8 @@ is v = getServerVersion >>= \x -> return $ x == Just v
143when' :: Monad m => m Bool -> m () -> m ()
144when' :: Monad m => m Bool -> m () -> m ()
144when' b f = b >>= \x -> when x f
145when' b f = b >>= \x -> when x f
145
146
146−(==~) :: (ApproxEq a, Show a) => a -> a -> Property
147+(==~) :: (ApproxEq a) => a -> a -> Property
147−a ==~ b = counterexample (show a ++ " !=~ " ++ show b) (a =~ b)
148+a ==~ b = counterexample (showApproxEq a ++ " !=~ " ++ showApproxEq b) (a =~ b)
148
149
149propJSON :: forall a. (Arbitrary a, ToJSON a, FromJSON a, Show a, ApproxEq a, Typeable a) => Proxy a -> Spec
150propJSON :: forall a. (Arbitrary a, ToJSON a, FromJSON a, Show a, ApproxEq a, Typeable a) => Proxy a -> Spec
150propJSON _ = prop testName $ \(a :: a) ->
151propJSON _ = prop testName $ \(a :: a) ->
@@ -451,14 +452,18 @@ class ApproxEq a where
451 default (=~) :: (Generic a, GApproxEq (Rep a)) => a -> a -> Bool
452 default (=~) :: (Generic a, GApproxEq (Rep a)) => a -> a -> Bool
452 a =~ b = gApproxEq (G.from a) (G.from b)
453 a =~ b = gApproxEq (G.from a) (G.from b)
453
454
455+ showApproxEq :: a -> String
456+ default showApproxEq :: (Show a) => a -> String
457+ showApproxEq = show
458+
454instance ApproxEq NominalDiffTime where (=~) = (==)
459instance ApproxEq NominalDiffTime where (=~) = (==)
455instance ApproxEq UTCTime where (=~) = (==)
460instance ApproxEq UTCTime where (=~) = (==)
456instance ApproxEq Text where (=~) = (==)
461instance ApproxEq Text where (=~) = (==)
457instance ApproxEq Bool where (=~) = (==)
462instance ApproxEq Bool where (=~) = (==)
458instance ApproxEq Int where (=~) = (==)
463instance ApproxEq Int where (=~) = (==)
459instance ApproxEq Double where (=~) = (==)
464instance ApproxEq Double where (=~) = (==)
460−instance ApproxEq a => ApproxEq (NonEmpty a)
465+instance (ApproxEq a, Show a) => ApproxEq (NonEmpty a)
461−instance ApproxEq a => ApproxEq (Maybe a)
466+instance (ApproxEq a, Show a) => ApproxEq (Maybe a)
462instance ApproxEq GeoPoint
467instance ApproxEq GeoPoint
463instance ApproxEq Regexp
468instance ApproxEq Regexp
464instance ApproxEq RangeValue
469instance ApproxEq RangeValue
@@ -575,12 +580,14 @@ instance ApproxEq AllocationPolicy
575instance ApproxEq Char
580instance ApproxEq Char
576instance ApproxEq Vers.Version where
581instance ApproxEq Vers.Version where
577 (=~) = (==)
582 (=~) = (==)
578−instance ApproxEq a => ApproxEq [a] where
583+instance (ApproxEq a, Show a) => ApproxEq [a] where
579 as =~ bs = and (zipWith (=~) as bs)
584 as =~ bs = and (zipWith (=~) as bs)
580−instance (ApproxEq l, ApproxEq r) => ApproxEq (Either l r) where
585+instance (ApproxEq l, Show l, ApproxEq r, Show r) => ApproxEq (Either l r) where
581 Left a =~ Left b = a =~ b
586 Left a =~ Left b = a =~ b
582 Right a =~ Right b = a =~ b
587 Right a =~ Right b = a =~ b
583 _ =~ _ = False
588 _ =~ _ = False
589+ showApproxEq (Left x) = "Left " <> showApproxEq x
590+ showApproxEq (Right x) = "Right " <> showApproxEq x
584instance ApproxEq NodeAttrFilter
591instance ApproxEq NodeAttrFilter
585instance ApproxEq NodeAttrName
592instance ApproxEq NodeAttrName
586instance ApproxEq BuildHash
593instance ApproxEq BuildHash
@@ -595,6 +602,10 @@ instance ApproxEq UpdatableIndexSetting where
595 RoutingAllocationRequire a =~ RoutingAllocationRequire b =
602 RoutingAllocationRequire a =~ RoutingAllocationRequire b =
596 NE.sort a =~ NE.sort b
603 NE.sort a =~ NE.sort b
597 a =~ b = a == b
604 a =~ b = a == b
605+ showApproxEq (RoutingAllocationInclude xs) = show (RoutingAllocationInclude (NE.sort xs))
606+ showApproxEq (RoutingAllocationExclude xs) = show (RoutingAllocationExclude (NE.sort xs))
607+ showApproxEq (RoutingAllocationRequire xs) = show (RoutingAllocationRequire (NE.sort xs))
608+ showApproxEq x = show x
598
609
599
610
600noDuplicates :: Eq a => [a] -> Bool
611noDuplicates :: Eq a => [a] -> Bool
@@ -655,8 +666,8 @@ getSource = fmap _source . foundResult
655grabFirst :: Either EsError (SearchResult a) -> Either EsError a
666grabFirst :: Either EsError (SearchResult a) -> Either EsError a
656grabFirst r =
667grabFirst r =
657 case fmap (hitSource . head . hits . searchHits) r of
668 case fmap (hitSource . head . hits . searchHits) r of
658− (Left e) -> Left e
669+ (Left e) -> Left e
659− (Right Nothing) -> Left (EsError 500 "Source was missing")
670+ (Right Nothing) -> Left (EsError 500 "Source was missing")
660 (Right (Just x)) -> Right x
671 (Right (Just x)) -> Right x
661
672
662-------------------------------------------------------------------------------
673-------------------------------------------------------------------------------
@@ -892,6 +903,21 @@ $(derive makeArbitrary ''CompoundFormat)
892$(derive makeArbitrary ''FsSnapshotRepo)
903$(derive makeArbitrary ''FsSnapshotRepo)
893$(derive makeArbitrary ''SnapshotRepoName)
904$(derive makeArbitrary ''SnapshotRepoName)
894
905
906+newtype UpdatableIndexSetting' = UpdatableIndexSetting' UpdatableIndexSetting
907+ deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
908+
909+instance Arbitrary UpdatableIndexSetting' where
910+ arbitrary = do
911+ settings <- arbitrary
912+ return $ UpdatableIndexSetting' $ case settings of
913+ RoutingAllocationInclude xs -> RoutingAllocationInclude (dropDuplicateAttrNames xs)
914+ RoutingAllocationExclude xs -> RoutingAllocationExclude (dropDuplicateAttrNames xs)
915+ RoutingAllocationRequire xs -> RoutingAllocationRequire (dropDuplicateAttrNames xs)
916+ x -> x
917+ where
918+ dropDuplicateAttrNames = NE.fromList . L.nubBy sameAttrName . NE.toList
919+ sameAttrName a b = nodeAttrFilterName a == nodeAttrFilterName b
920+
895main :: IO ()
921main :: IO ()
896main = hspec $ do
922main = hspec $ do
897
923
@@ -1808,7 +1834,7 @@ main = hspec $ do
1808 propJSON (Proxy :: Proxy Term)
1834 propJSON (Proxy :: Proxy Term)
1809 propJSON (Proxy :: Proxy MultiMatchQuery)
1835 propJSON (Proxy :: Proxy MultiMatchQuery)
1810 propJSON (Proxy :: Proxy IndexSettings)
1836 propJSON (Proxy :: Proxy IndexSettings)
1811− propJSON (Proxy :: Proxy UpdatableIndexSetting)
1837+ propJSON (Proxy :: Proxy UpdatableIndexSetting')
1812 propJSON (Proxy :: Proxy ReplicaBounds)
1838 propJSON (Proxy :: Proxy ReplicaBounds)
1813 propJSON (Proxy :: Proxy Bytes)
1839 propJSON (Proxy :: Proxy Bytes)
1814 propJSON (Proxy :: Proxy AllocationPolicy)
1840 propJSON (Proxy :: Proxy AllocationPolicy)