@@ -18,51 +18,30 @@
1818#endif
1919module Main where
2020
21−import Control.Applicative
21+import Test.Import
22+
2223import Control.Error hiding (Script)
23−import Control.Exception (evaluate)
24−import Control.Monad
25−import Control.Monad.Catch
26−import Control.Monad.Reader
27−import Data.Aeson
28−import Data.Aeson.TH
29−import Data.Aeson.Types (parseEither)
30−import qualified Data.ByteString.Lazy.Char8 as BL8
3124import qualified Data.HashMap.Strict as HM
3225import Data.List (nub)
3326import qualified Data.List as L
3427import Data.List.NonEmpty (NonEmpty (..))
3528import qualified Data.List.NonEmpty as NE
3629import qualified Data.Map.Strict as M
37−import Data.Monoid
38−import Data.Ord (comparing)
39−import Data.Proxy
4030import Data.Text (Text)
4131import qualified Data.Text as T
4232import Data.Time.Calendar (Day (..), fromGregorian)
43−import Data.Time.Clock (NominalDiffTime, UTCTime (..),
33+import Data.Time.Clock (UTCTime (..),
4434 secondsToDiffTime)
45−import Data.Typeable
4635import qualified Data.Vector as V
4736import qualified Data.Version as Vers
48−import Database.V5.Bloodhound
49−import Lens.Micro
50−import Lens.Micro.Aeson
37+import qualified Database.V5.Bloodhound
5138import qualified Lens.Micro.Aeson as LMA
52−import Network.HTTP.Client hiding (Proxy)
5339import qualified Network.HTTP.Types.Method as NHTM
5440import qualified Network.HTTP.Types.Status as NHTS
5541import qualified Network.URI as URI
5642import Prelude hiding (filter)
57−import System.IO.Temp
58−import System.PosixCompat.Files
59−import Test.Hspec
60−import Test.QuickCheck.Property.Monoid (T (..), eq, prop_Monoid)
6143
62−import Test.Hspec.QuickCheck (prop)
63−import Test.QuickCheck
64−import Test.QuickCheck.TH.Generators
65−-- import Text.Pretty.Simple (pPrint)
44+import qualified Test.JSON as JSON
6645
6746testServer :: Server
6847testServer = Server "http://localhost:9200"
@@ -156,22 +135,6 @@ is v = getServerVersion >>= \x -> return $ x == Just v
156135when' :: Monad m => m Bool -> m () -> m ()
157136when' b f = b >>= \x -> when x f
158137
159−propJSON :: forall a
160− . ( Arbitrary a
161− , ToJSON a
162− , FromJSON a
163− , Show a
164− , Eq a
165− , Typeable a
166− )
167− => Proxy a -> Spec
168−propJSON _ = prop testName $ \(a :: a) ->
169− let jsonStr = "via " <> BL8.unpack (encode a)
170− in counterexample jsonStr (parseEither parseJSON (toJSON a)
171− === Right a)
172− where testName = show ty <> " FromJSON/ToJSON roundtrips"
173− ty = typeOf (undefined :: a)
174−
175138data Location = Location { lat :: Double
176139 , lon :: Double } deriving (Eq, Show)
177140
@@ -451,114 +414,9 @@ instance FromJSON BulkTest where
451414 t <- o .: "name"
452415 BulkTest <$> parseJSON t
453416
454−-- | Typeclass for "equal where it matters". Use this to specify
455−-- less-strict equivalence for things such as lists that can wind up
456−-- in an unpredictable order
457−class ApproxEq a where
458− (=~) :: a -> a -> Bool
459−
460− showApproxEq :: a -> String
461− default showApproxEq :: (Show a) => a -> String
462− showApproxEq = show
463−
464−(==~) :: (ApproxEq a) => a -> a -> Property
465−a ==~ b = counterexample (showApproxEq a ++ " !=~ " ++ showApproxEq b) (a =~ b)
466−
467−propApproxJSON :: forall a
468− . ( Arbitrary a
469− , ToJSON a
470− , FromJSON a
471− , Show a
472− , ApproxEq a
473− , Typeable a
474− )
475− => Proxy a -> Spec
476−propApproxJSON _ = prop testName $ \(a :: a) ->
477− let jsonStr = "via " <> BL8.unpack (encode a)
478− in counterexample jsonStr (parseEither parseJSON (toJSON a)
479− ==~ Right a)
480− where testName = show ty <> " FromJSON/ToJSON roundtrips"
481− ty = typeOf (undefined :: a)
482−
483−instance ApproxEq NominalDiffTime where (=~) = (==)
484−instance ApproxEq Bool where (=~) = (==)
485−instance ApproxEq Int where (=~) = (==)
486−instance (Eq a, Show a) => ApproxEq (Maybe a) where (=~) = (==)
487−instance ApproxEq Char where
488− (=~) = (==)
489−
490−instance ApproxEq NodeAttrFilter where (=~) = (==)
491−instance ApproxEq NodeAttrName where (=~) = (==)
492−instance (Eq a, Show a) => ApproxEq (NonEmpty a) where (=~) = (==)
493−instance (ApproxEq l, Show l, ApproxEq r, Show r) => ApproxEq (Either l r) where
494− Left a =~ Left b = a =~ b
495− Right a =~ Right b = a =~ b
496− _ =~ _ = False
497− showApproxEq (Left x) = "Left " <> showApproxEq x
498− showApproxEq (Right x) = "Right " <> showApproxEq x
499−instance (ApproxEq a, Show a) => ApproxEq [a] where
500− as =~ bs = and (zipWith (=~) as bs)
501−instance ApproxEq ReplicaCount where (=~) = (==)
502−instance ApproxEq ReplicaBounds where (=~) = (==)
503−instance ApproxEq Bytes where (=~) = (==)
504−instance ApproxEq AllocationPolicy where (=~) = (==)
505−instance ApproxEq InitialShardCount where (=~) = (==)
506−instance ApproxEq FSType where (=~) = (==)
507−
508417noDuplicates :: Eq a => [a] -> Bool
509418noDuplicates xs = nub xs == xs
510419
511−instance Arbitrary NominalDiffTime where
512− arbitrary = fromInteger <$> arbitrary
513−
514−#if !MIN_VERSION_QuickCheck(2,8,0)
515−instance (Arbitrary k, Ord k, Arbitrary v) => Arbitrary (M.Map k v) where
516− arbitrary = M.fromList <$> arbitrary
517−#endif
518−
519−instance Arbitrary Text where
520− arbitrary = T.pack <$> arbitrary
521−
522−instance Arbitrary UTCTime where
523− arbitrary = UTCTime
524− <$> arbitrary
525− <*> (fromRational . toRational <$> choose (0::Double, 86400))
526−
527−instance Arbitrary Day where
528− arbitrary = ModifiedJulianDay <$> (2000 +) <$> arbitrary
529− shrink = (ModifiedJulianDay <$>) . shrink . toModifiedJulianDay
530−
531−#if !MIN_VERSION_QuickCheck(2,9,0)
532−instance Arbitrary a => Arbitrary (NonEmpty a) where
533− arbitrary = liftA2 (:|) arbitrary arbitrary
534−#endif
535−
536−arbitraryScore :: Gen Score
537−arbitraryScore = fmap getPositive <$> arbitrary
538−
539−instance (Arbitrary a, Typeable a) => Arbitrary (Hit a) where
540− arbitrary = Hit <$> arbitrary
541− <*> arbitrary
542− <*> arbitrary
543− <*> arbitraryScore
544− <*> arbitrary
545− <*> arbitrary
546− <*> arbitrary
547−
548−instance Arbitrary HitFields where
549− arbitrary = pure (HitFields M.empty)
550− shrink = const []
551−
552−instance (Arbitrary a, Typeable a) => Arbitrary (SearchHits a) where
553− arbitrary = reduceSize $ do
554− tot <- getPositive <$> arbitrary
555− score <- arbitraryScore
556− hs <- arbitrary
557− return $ SearchHits tot score hs
558−
559−
560−reduceSize :: Gen a -> Gen a
561−reduceSize f = sized $ \n -> resize (n `div` 2) f
562420
563421getSource :: EsResult a -> Maybe a
564422getSource = fmap _source . foundResult
@@ -570,487 +428,9 @@ grabFirst r =
570428 (Right Nothing) -> Left (EsError 500 "Source was missing")
571429 (Right (Just x)) -> Right x
572430
573−-------------------------------------------------------------------------------
574−arbitraryAlphaNum :: Gen Char
575−arbitraryAlphaNum = oneof [choose ('a', 'z')
576− ,choose ('A','Z')
577− , choose ('0', '9')]
578−
579−instance Arbitrary RoutingValue where
580− arbitrary = RoutingValue . T.pack <$> listOf1 arbitraryAlphaNum
581−
582−instance Arbitrary AliasRouting where
583− arbitrary = oneof [allAlias
584− ,one
585− ,theOther
586− ,both']
587− where one = GranularAliasRouting
588− <$> (Just <$> arbitrary)
589− <*> pure Nothing
590− theOther = GranularAliasRouting Nothing
591− <$> (Just <$> arbitrary)
592− both' = GranularAliasRouting
593− <$> (Just <$> arbitrary)
594− <*> (Just <$> arbitrary)
595− allAlias = AllAliasRouting <$> arbitrary
596−
597−
598−
599−instance Arbitrary FieldName where
600− arbitrary =
601− FieldName
602− . T.pack
603− <$> listOf1 arbitraryAlphaNum
604−
605−
606−#if MIN_VERSION_base(4,10,0)
607−-- Test.QuickCheck.Modifiers
608−
609−qcNonEmptyToNonEmpty :: NonEmptyList a -> NonEmpty a
610−qcNonEmptyToNonEmpty (NonEmpty (a : xs)) = (a :| xs)
611−qcNonEmptyToNonEmpty (NonEmpty []) = error "NonEmpty was empty!"
612−
613−instance Arbitrary a => Arbitrary (NonEmpty a) where
614− arbitrary =
615− qcNonEmptyToNonEmpty
616− <$> arbitrary
617−#endif
618−instance Arbitrary ScriptFields where
619− arbitrary =
620− pure $ ScriptFields $
621− HM.fromList []
622−
623− shrink = const []
624−
625−instance Arbitrary ScriptParams where
626− arbitrary =
627− pure $ ScriptParams $
628− HM.fromList [ ("a", Number 42)
629− , ("b", String "forty two")
630− ]
631−
632− shrink = const []
633−
634−instance Arbitrary RegexpFlags where
635− arbitrary = oneof [ pure AllRegexpFlags
636− , pure NoRegexpFlags
637− , SomeRegexpFlags <$> genUniqueFlags
638− ]
639− where genUniqueFlags =
640− NE.fromList . nub
641− <$> listOf1 arbitrary
642−
643−instance Arbitrary IndexAliasCreate where
644− arbitrary =
645− IndexAliasCreate
646− <$> arbitrary
647− <*> reduceSize arbitrary
648−
649−instance Arbitrary Query where
650− arbitrary =
651− reduceSize
652− $ oneof [ TermQuery <$> arbitrary <*> arbitrary
653− , TermsQuery <$> arbitrary <*> arbitrary
654− , QueryMatchQuery <$> arbitrary
655− , QueryMultiMatchQuery <$> arbitrary
656− , QueryBoolQuery <$> arbitrary
657− , QueryBoostingQuery <$> arbitrary
658− , QueryCommonTermsQuery <$> arbitrary
659− , ConstantScoreQuery <$> arbitrary <*> arbitrary
660− , QueryDisMaxQuery <$> arbitrary
661− , QueryFuzzyLikeThisQuery <$> arbitrary
662− , QueryFuzzyLikeFieldQuery <$> arbitrary
663− , QueryFuzzyQuery <$> arbitrary
664− , QueryHasChildQuery <$> arbitrary
665− , QueryHasParentQuery <$> arbitrary
666− , IdsQuery <$> arbitrary <*> arbitrary
667− , QueryIndicesQuery <$> arbitrary
668− , MatchAllQuery <$> arbitrary
669− , QueryMoreLikeThisQuery <$> arbitrary
670− , QueryMoreLikeThisFieldQuery <$> arbitrary
671− , QueryNestedQuery <$> arbitrary
672− , QueryPrefixQuery <$> arbitrary
673− , QueryQueryStringQuery <$> arbitrary
674− , QuerySimpleQueryStringQuery <$> arbitrary
675− , QueryRangeQuery <$> arbitrary
676− , QueryRegexpQuery <$> arbitrary
677− , QueryTemplateQueryInline <$> arbitrary
678− ]
679− -- TODO: Implement shrink
680− -- shrink = genericShrink
681−
682−instance Arbitrary Filter where
683− arbitrary =
684− Filter <$> arbitrary
685− shrink (Filter q) =
686− Filter <$> shrink q
687−
688−instance Arbitrary ReplicaBounds where
689− arbitrary = oneof [ replicasBounded
690− , replicasLowerBounded
691− , pure ReplicasUnbounded
692− ]
693− where replicasBounded = do
694− Positive a <- arbitrary
695− Positive b <- arbitrary
696− return (ReplicasBounded a b)
697− replicasLowerBounded = do
698− Positive a <- arbitrary
699− return (ReplicasLowerBounded a)
700−
701−instance Arbitrary NodeAttrName where
702− arbitrary =
703− NodeAttrName
704− . T.pack
705− <$> listOf1 arbitraryAlphaNum
706−
707−
708−instance Arbitrary NodeAttrFilter where
709− arbitrary = do
710− n <- arbitrary
711− s:ss <- listOf1 (listOf1 arbitraryAlphaNum)
712− let ts = T.pack <$> s :| ss
713− return (NodeAttrFilter n ts)
714−
715−instance Arbitrary VersionNumber where
716− arbitrary = mk . fmap getPositive . getNonEmpty <$> arbitrary
717− where
718− mk versions = VersionNumber (Vers.Version versions [])
719−
720−instance Arbitrary TemplateQueryKeyValuePairs where
721− arbitrary = TemplateQueryKeyValuePairs . HM.fromList <$> arbitrary
722− shrink (TemplateQueryKeyValuePairs x) = map (TemplateQueryKeyValuePairs . HM.fromList) . shrink $ HM.toList x
723−
724−makeArbitrary ''IndexName
725−instance Arbitrary IndexName where arbitrary = arbitraryIndexName
726−makeArbitrary ''MappingName
727−instance Arbitrary MappingName where arbitrary = arbitraryMappingName
728−makeArbitrary ''DocId
729−instance Arbitrary DocId where arbitrary = arbitraryDocId
730−makeArbitrary ''Version
731−instance Arbitrary Version where arbitrary = arbitraryVersion
732−makeArbitrary ''BuildHash
733−instance Arbitrary BuildHash where arbitrary = arbitraryBuildHash
734−makeArbitrary ''IndexAliasRouting
735−instance Arbitrary IndexAliasRouting where arbitrary = arbitraryIndexAliasRouting
736−makeArbitrary ''ShardCount
737−instance Arbitrary ShardCount where arbitrary = arbitraryShardCount
738−makeArbitrary ''ReplicaCount
739−instance Arbitrary ReplicaCount where arbitrary = arbitraryReplicaCount
740−makeArbitrary ''TemplateName
741−instance Arbitrary TemplateName where arbitrary = arbitraryTemplateName
742−makeArbitrary ''TemplatePattern
743−instance Arbitrary TemplatePattern where arbitrary = arbitraryTemplatePattern
744−makeArbitrary ''QueryString
745−instance Arbitrary QueryString where arbitrary = arbitraryQueryString
746−makeArbitrary ''CacheName
747−instance Arbitrary CacheName where arbitrary = arbitraryCacheName
748−makeArbitrary ''CacheKey
749−instance Arbitrary CacheKey where arbitrary = arbitraryCacheKey
750−makeArbitrary ''Existence
751−instance Arbitrary Existence where arbitrary = arbitraryExistence
752−makeArbitrary ''CutoffFrequency
753−instance Arbitrary CutoffFrequency where arbitrary = arbitraryCutoffFrequency
754−makeArbitrary ''Analyzer
755−instance Arbitrary Analyzer where arbitrary = arbitraryAnalyzer
756−makeArbitrary ''MaxExpansions
757−instance Arbitrary MaxExpansions where arbitrary = arbitraryMaxExpansions
758−makeArbitrary ''Lenient
759−instance Arbitrary Lenient where arbitrary = arbitraryLenient
760−makeArbitrary ''Tiebreaker
761−instance Arbitrary Tiebreaker where arbitrary = arbitraryTiebreaker
762−makeArbitrary ''Boost
763−instance Arbitrary Boost where arbitrary = arbitraryBoost
764−makeArbitrary ''BoostTerms
765−instance Arbitrary BoostTerms where arbitrary = arbitraryBoostTerms
766−makeArbitrary ''MinimumMatch
767−instance Arbitrary MinimumMatch where arbitrary = arbitraryMinimumMatch
768−makeArbitrary ''DisableCoord
769−instance Arbitrary DisableCoord where arbitrary = arbitraryDisableCoord
770−makeArbitrary ''IgnoreTermFrequency
771−instance Arbitrary IgnoreTermFrequency where arbitrary = arbitraryIgnoreTermFrequency
772−makeArbitrary ''MinimumTermFrequency
773−instance Arbitrary MinimumTermFrequency where arbitrary = arbitraryMinimumTermFrequency
774−makeArbitrary ''MaxQueryTerms
775−instance Arbitrary MaxQueryTerms where arbitrary = arbitraryMaxQueryTerms
776−makeArbitrary ''Fuzziness
777−instance Arbitrary Fuzziness where arbitrary = arbitraryFuzziness
778−makeArbitrary ''PrefixLength
779−instance Arbitrary PrefixLength where arbitrary = arbitraryPrefixLength
780−makeArbitrary ''TypeName
781−instance Arbitrary TypeName where arbitrary = arbitraryTypeName
782−makeArbitrary ''PercentMatch
783−instance Arbitrary PercentMatch where arbitrary = arbitraryPercentMatch
784−makeArbitrary ''StopWord
785−instance Arbitrary StopWord where arbitrary = arbitraryStopWord
786−makeArbitrary ''QueryPath
787−instance Arbitrary QueryPath where arbitrary = arbitraryQueryPath
788−makeArbitrary ''AllowLeadingWildcard
789−instance Arbitrary AllowLeadingWildcard where arbitrary = arbitraryAllowLeadingWildcard
790−makeArbitrary ''LowercaseExpanded
791−instance Arbitrary LowercaseExpanded where arbitrary = arbitraryLowercaseExpanded
792−makeArbitrary ''EnablePositionIncrements
793−instance Arbitrary EnablePositionIncrements where arbitrary = arbitraryEnablePositionIncrements
794−makeArbitrary ''AnalyzeWildcard
795−instance Arbitrary AnalyzeWildcard where arbitrary = arbitraryAnalyzeWildcard
796−makeArbitrary ''GeneratePhraseQueries
797−instance Arbitrary GeneratePhraseQueries where arbitrary = arbitraryGeneratePhraseQueries
798−makeArbitrary ''Locale
799−instance Arbitrary Locale where arbitrary = arbitraryLocale
800−makeArbitrary ''MaxWordLength
801−instance Arbitrary MaxWordLength where arbitrary = arbitraryMaxWordLength
802−makeArbitrary ''MinWordLength
803−instance Arbitrary MinWordLength where arbitrary = arbitraryMinWordLength
804−makeArbitrary ''PhraseSlop
805−instance Arbitrary PhraseSlop where arbitrary = arbitraryPhraseSlop
806−makeArbitrary ''MinDocFrequency
807−instance Arbitrary MinDocFrequency where arbitrary = arbitraryMinDocFrequency
808−makeArbitrary ''MaxDocFrequency
809−instance Arbitrary MaxDocFrequency where arbitrary = arbitraryMaxDocFrequency
810−makeArbitrary ''Regexp
811−instance Arbitrary Regexp where arbitrary = arbitraryRegexp
812−makeArbitrary ''SimpleQueryStringQuery
813−instance Arbitrary SimpleQueryStringQuery where arbitrary = arbitrarySimpleQueryStringQuery
814−makeArbitrary ''FieldOrFields
815−instance Arbitrary FieldOrFields where arbitrary = arbitraryFieldOrFields
816−makeArbitrary ''SimpleQueryFlag
817−instance Arbitrary SimpleQueryFlag where arbitrary = arbitrarySimpleQueryFlag
818−makeArbitrary ''RegexpQuery
819−instance Arbitrary RegexpQuery where arbitrary = arbitraryRegexpQuery
820−makeArbitrary ''QueryStringQuery
821−instance Arbitrary QueryStringQuery where arbitrary = arbitraryQueryStringQuery
822−makeArbitrary ''RangeQuery
823−instance Arbitrary RangeQuery where arbitrary = arbitraryRangeQuery
824−makeArbitrary ''RangeValue
825−instance Arbitrary RangeValue where arbitrary = arbitraryRangeValue
826−makeArbitrary ''PrefixQuery
827−instance Arbitrary PrefixQuery where arbitrary = arbitraryPrefixQuery
828−makeArbitrary ''NestedQuery
829−instance Arbitrary NestedQuery where arbitrary = arbitraryNestedQuery
830−makeArbitrary ''MoreLikeThisFieldQuery
831−instance Arbitrary MoreLikeThisFieldQuery where arbitrary = arbitraryMoreLikeThisFieldQuery
832−makeArbitrary ''MoreLikeThisQuery
833−instance Arbitrary MoreLikeThisQuery where arbitrary = arbitraryMoreLikeThisQuery
834−makeArbitrary ''IndicesQuery
835−instance Arbitrary IndicesQuery where arbitrary = arbitraryIndicesQuery
836−makeArbitrary ''HasParentQuery
837−instance Arbitrary HasParentQuery where arbitrary = arbitraryHasParentQuery
838−makeArbitrary ''HasChildQuery
839−instance Arbitrary HasChildQuery where arbitrary = arbitraryHasChildQuery
840−makeArbitrary ''FuzzyQuery
841−instance Arbitrary FuzzyQuery where arbitrary = arbitraryFuzzyQuery
842−makeArbitrary ''FuzzyLikeFieldQuery
843−instance Arbitrary FuzzyLikeFieldQuery where arbitrary = arbitraryFuzzyLikeFieldQuery
844−makeArbitrary ''FuzzyLikeThisQuery
845−instance Arbitrary FuzzyLikeThisQuery where arbitrary = arbitraryFuzzyLikeThisQuery
846−makeArbitrary ''DisMaxQuery
847−instance Arbitrary DisMaxQuery where arbitrary = arbitraryDisMaxQuery
848−makeArbitrary ''CommonTermsQuery
849−instance Arbitrary CommonTermsQuery where arbitrary = arbitraryCommonTermsQuery
850−makeArbitrary ''DistanceRange
851−instance Arbitrary DistanceRange where arbitrary = arbitraryDistanceRange
852−makeArbitrary ''MultiMatchQuery
853−instance Arbitrary MultiMatchQuery where arbitrary = arbitraryMultiMatchQuery
854−makeArbitrary ''LessThanD
855−instance Arbitrary LessThanD where arbitrary = arbitraryLessThanD
856−makeArbitrary ''LessThanEqD
857−instance Arbitrary LessThanEqD where arbitrary = arbitraryLessThanEqD
858−makeArbitrary ''GreaterThanD
859−instance Arbitrary GreaterThanD where arbitrary = arbitraryGreaterThanD
860−makeArbitrary ''GreaterThanEqD
861−instance Arbitrary GreaterThanEqD where arbitrary = arbitraryGreaterThanEqD
862−makeArbitrary ''LessThan
863−instance Arbitrary LessThan where arbitrary = arbitraryLessThan
864−makeArbitrary ''LessThanEq
865−instance Arbitrary LessThanEq where arbitrary = arbitraryLessThanEq
866−makeArbitrary ''GreaterThan
867−instance Arbitrary GreaterThan where arbitrary = arbitraryGreaterThan
868−makeArbitrary ''GreaterThanEq
869−instance Arbitrary GreaterThanEq where arbitrary = arbitraryGreaterThanEq
870−makeArbitrary ''GeoPoint
871−instance Arbitrary GeoPoint where arbitrary = arbitraryGeoPoint
872−makeArbitrary ''NullValue
873−instance Arbitrary NullValue where arbitrary = arbitraryNullValue
874−makeArbitrary ''MinimumMatchHighLow
875−instance Arbitrary MinimumMatchHighLow where arbitrary = arbitraryMinimumMatchHighLow
876−makeArbitrary ''CommonMinimumMatch
877−instance Arbitrary CommonMinimumMatch where arbitrary = arbitraryCommonMinimumMatch
878−makeArbitrary ''BoostingQuery
879−instance Arbitrary BoostingQuery where arbitrary = arbitraryBoostingQuery
880−makeArbitrary ''BoolQuery
881−instance Arbitrary BoolQuery where arbitrary = arbitraryBoolQuery
882−makeArbitrary ''MatchQuery
883−instance Arbitrary MatchQuery where arbitrary = arbitraryMatchQuery
884−makeArbitrary ''MultiMatchQueryType
885−instance Arbitrary MultiMatchQueryType where arbitrary = arbitraryMultiMatchQueryType
886−makeArbitrary ''BooleanOperator
887−instance Arbitrary BooleanOperator where arbitrary = arbitraryBooleanOperator
888−makeArbitrary ''ZeroTermsQuery
889−instance Arbitrary ZeroTermsQuery where arbitrary = arbitraryZeroTermsQuery
890−makeArbitrary ''MatchQueryType
891−instance Arbitrary MatchQueryType where arbitrary = arbitraryMatchQueryType
892−makeArbitrary ''SearchAliasRouting
893−instance Arbitrary SearchAliasRouting where arbitrary = arbitrarySearchAliasRouting
894−makeArbitrary ''ScoreType
895−instance Arbitrary ScoreType where arbitrary = arbitraryScoreType
896−makeArbitrary ''Distance
897−instance Arbitrary Distance where arbitrary = arbitraryDistance
898−makeArbitrary ''DistanceUnit
899−instance Arbitrary DistanceUnit where arbitrary = arbitraryDistanceUnit
900−makeArbitrary ''DistanceType
901−instance Arbitrary DistanceType where arbitrary = arbitraryDistanceType
902−makeArbitrary ''OptimizeBbox
903−instance Arbitrary OptimizeBbox where arbitrary = arbitraryOptimizeBbox
904−makeArbitrary ''GeoBoundingBoxConstraint
905−instance Arbitrary GeoBoundingBoxConstraint where arbitrary = arbitraryGeoBoundingBoxConstraint
906−makeArbitrary ''GeoFilterType
907−instance Arbitrary GeoFilterType where arbitrary = arbitraryGeoFilterType
908−makeArbitrary ''GeoBoundingBox
909−instance Arbitrary GeoBoundingBox where arbitrary = arbitraryGeoBoundingBox
910−makeArbitrary ''LatLon
911−instance Arbitrary LatLon where arbitrary = arbitraryLatLon
912−makeArbitrary ''RangeExecution
913−instance Arbitrary RangeExecution where arbitrary = arbitraryRangeExecution
914−makeArbitrary ''RegexpFlag
915−instance Arbitrary RegexpFlag where arbitrary = arbitraryRegexpFlag
916−makeArbitrary ''BoolMatch
917−instance Arbitrary BoolMatch where arbitrary = arbitraryBoolMatch
918−makeArbitrary ''Term
919−instance Arbitrary Term where arbitrary = arbitraryTerm
920−makeArbitrary ''IndexSettings
921−instance Arbitrary IndexSettings where arbitrary = arbitraryIndexSettings
922−makeArbitrary ''TokenChar
923−instance Arbitrary TokenChar where arbitrary = arbitraryTokenChar
924−makeArbitrary ''Ngram
925−instance Arbitrary Ngram where arbitrary = arbitraryNgram
926−makeArbitrary ''TokenizerDefinition
927−instance Arbitrary TokenizerDefinition where arbitrary = arbitraryTokenizerDefinition
928−makeArbitrary ''TokenFilter
929−instance Arbitrary TokenFilter where arbitrary = arbitraryTokenFilter
930−makeArbitrary ''TokenFilterDefinition
931−instance Arbitrary TokenFilterDefinition where arbitrary = arbitraryTokenFilterDefinition
932−makeArbitrary ''Language
933−instance Arbitrary Language where arbitrary = arbitraryLanguage
934−makeArbitrary ''Shingle
935−instance Arbitrary Shingle where arbitrary = arbitraryShingle
936−makeArbitrary ''AnalyzerDefinition
937−instance Arbitrary AnalyzerDefinition where arbitrary = arbitraryAnalyzerDefinition
938−makeArbitrary ''Analysis
939−instance Arbitrary Analysis where arbitrary = arbitraryAnalysis
940−makeArbitrary ''Tokenizer
941−instance Arbitrary Tokenizer where arbitrary = arbitraryTokenizer
942−makeArbitrary ''UpdatableIndexSetting
943−instance Arbitrary UpdatableIndexSetting where
944− arbitrary = arbitraryUpdatableIndexSetting
945−makeArbitrary ''Compression
946−instance Arbitrary Compression where arbitrary = arbitraryCompression
947−makeArbitrary ''Bytes
948−instance Arbitrary Bytes where arbitrary = arbitraryBytes
949−makeArbitrary ''AllocationPolicy
950−instance Arbitrary AllocationPolicy where arbitrary = arbitraryAllocationPolicy
951−makeArbitrary ''InitialShardCount
952−instance Arbitrary InitialShardCount where arbitrary = arbitraryInitialShardCount
953−makeArbitrary ''FSType
954−instance Arbitrary FSType where arbitrary = arbitraryFSType
955−makeArbitrary ''CompoundFormat
956−instance Arbitrary CompoundFormat where arbitrary = arbitraryCompoundFormat
957−makeArbitrary ''FsSnapshotRepo
958−instance Arbitrary FsSnapshotRepo where arbitrary = arbitraryFsSnapshotRepo
959−makeArbitrary ''SnapshotRepoName
960−instance Arbitrary SnapshotRepoName where arbitrary = arbitrarySnapshotRepoName
961−makeArbitrary ''TemplateQueryInline
962−instance Arbitrary TemplateQueryInline where arbitrary = arbitraryTemplateQueryInline
963−makeArbitrary ''DirectGeneratorSuggestModeTypes
964−instance Arbitrary DirectGeneratorSuggestModeTypes where arbitrary = arbitraryDirectGeneratorSuggestModeTypes
965−makeArbitrary ''DirectGenerators
966−instance Arbitrary DirectGenerators where arbitrary = arbitraryDirectGenerators
967−makeArbitrary ''PhraseSuggesterCollate
968−instance Arbitrary PhraseSuggesterCollate where arbitrary = arbitraryPhraseSuggesterCollate
969−makeArbitrary ''PhraseSuggesterHighlighter
970−instance Arbitrary PhraseSuggesterHighlighter where arbitrary = arbitraryPhraseSuggesterHighlighter
971−makeArbitrary ''Size
972−instance Arbitrary Size where arbitrary = arbitrarySize
973−makeArbitrary ''PhraseSuggester
974−instance Arbitrary PhraseSuggester where arbitrary = arbitraryPhraseSuggester
975−makeArbitrary ''SuggestType
976−instance Arbitrary SuggestType where arbitrary = arbitrarySuggestType
977−makeArbitrary ''Suggest
978−instance Arbitrary Suggest where arbitrary = arbitrarySuggest
979−
980−makeArbitrary ''FunctionScoreQuery
981−instance Arbitrary FunctionScoreQuery where arbitrary = arbitraryFunctionScoreQuery
982−
983−makeArbitrary ''FunctionScoreFunction
984−instance Arbitrary FunctionScoreFunction where arbitrary = arbitraryFunctionScoreFunction
985−makeArbitrary ''FunctionScoreFunctions
986−instance Arbitrary FunctionScoreFunctions where arbitrary = arbitraryFunctionScoreFunctions
987−makeArbitrary ''ComponentFunctionScoreFunction
988−instance Arbitrary ComponentFunctionScoreFunction where arbitrary = arbitraryComponentFunctionScoreFunction
989−makeArbitrary ''Script
990−instance Arbitrary Script where arbitrary = arbitraryScript
991−makeArbitrary ''ScriptLanguage
992−instance Arbitrary ScriptLanguage where arbitrary = arbitraryScriptLanguage
993−makeArbitrary ''ScriptInline
994−instance Arbitrary ScriptInline where arbitrary = arbitraryScriptInline
995−makeArbitrary ''ScriptId
996−instance Arbitrary ScriptId where arbitrary = arbitraryScriptId
997−makeArbitrary ''ScoreMode
998−instance Arbitrary ScoreMode where arbitrary = arbitraryScoreMode
999−makeArbitrary ''BoostMode
1000−instance Arbitrary BoostMode where arbitrary = arbitraryBoostMode
1001−makeArbitrary ''Seed
1002−instance Arbitrary Seed where arbitrary = arbitrarySeed
1003−makeArbitrary ''FieldValueFactor
1004−instance Arbitrary FieldValueFactor where arbitrary = arbitraryFieldValueFactor
1005−makeArbitrary ''Weight
1006−instance Arbitrary Weight where arbitrary = arbitraryWeight
1007−makeArbitrary ''Factor
1008−instance Arbitrary Factor where arbitrary = arbitraryFactor
1009−makeArbitrary ''FactorMissingFieldValue
1010−instance Arbitrary FactorMissingFieldValue where arbitrary = arbitraryFactorMissingFieldValue
1011−makeArbitrary ''FactorModifier
1012−instance Arbitrary FactorModifier where arbitrary = arbitraryFactorModifier
1013−
1014−newtype UpdatableIndexSetting' =
1015− UpdatableIndexSetting' UpdatableIndexSetting
1016− deriving (Show, Eq, ToJSON, FromJSON, ApproxEq, Typeable)
1017−
1018−instance Arbitrary UpdatableIndexSetting' where
1019− arbitrary = do
1020− settings <- arbitrary
1021− return $ UpdatableIndexSetting' $ case settings of
1022− RoutingAllocationInclude xs ->
1023− RoutingAllocationInclude (dropDuplicateAttrNames xs)
1024− RoutingAllocationExclude xs ->
1025− RoutingAllocationExclude (dropDuplicateAttrNames xs)
1026− RoutingAllocationRequire xs ->
1027− RoutingAllocationRequire (dropDuplicateAttrNames xs)
1028− x -> x
1029− where
1030− dropDuplicateAttrNames =
1031− NE.fromList . L.nubBy sameAttrName . NE.toList
1032− sameAttrName a b =
1033− nodeAttrFilterName a == nodeAttrFilterName b
1034− -- shrink (UpdatableIndexSetting' x) = map UpdatableIndexSetting' (shrink x)
1035−
1036−-- | Due to the way nodeattrfilters get serialized here, they may come
1037−-- out in a different order, but they are morally equivalent
1038−instance ApproxEq UpdatableIndexSetting where
1039− RoutingAllocationInclude a =~ RoutingAllocationInclude b =
1040− NE.sort a =~ NE.sort b
1041− RoutingAllocationExclude a =~ RoutingAllocationExclude b =
1042− NE.sort a =~ NE.sort b
1043− RoutingAllocationRequire a =~ RoutingAllocationRequire b =
1044− NE.sort a =~ NE.sort b
1045− a =~ b = a == b
1046− showApproxEq (RoutingAllocationInclude xs) = show (RoutingAllocationInclude (NE.sort xs))
1047− showApproxEq (RoutingAllocationExclude xs) = show (RoutingAllocationExclude (NE.sort xs))
1048− showApproxEq (RoutingAllocationRequire xs) = show (RoutingAllocationRequire (NE.sort xs))
1049− showApproxEq x = show x
1050−
1051431main :: IO ()
1052432main = hspec $ do
1053−
433+ JSON.spec
1054434 describe "index create/delete API" $ do
1055435 it "creates and then deletes the requested index" $ withTestEnv $ do
1056436 -- priming state.
@@ -1881,124 +1261,3 @@ main = hspec $ do
18811261 let Just results =
18821262 hitFields (head (hits (searchHits sr)))
18831263 liftIO $ results `shouldBe` (HitFields (M.fromList [("test1", [Number 20000.0])]))
1884−
1885− describe "Exact isomorphism JSON instances" $ do
1886− propJSON (Proxy :: Proxy Version)
1887− propJSON (Proxy :: Proxy IndexName)
1888− propJSON (Proxy :: Proxy MappingName)
1889− propJSON (Proxy :: Proxy DocId)
1890− propJSON (Proxy :: Proxy IndexAliasRouting)
1891− propJSON (Proxy :: Proxy RoutingValue)
1892− propJSON (Proxy :: Proxy ShardCount)
1893− propJSON (Proxy :: Proxy ReplicaCount)
1894− propJSON (Proxy :: Proxy TemplateName)
1895− propJSON (Proxy :: Proxy TemplatePattern)
1896− propJSON (Proxy :: Proxy QueryString)
1897− propJSON (Proxy :: Proxy FieldName)
1898− propJSON (Proxy :: Proxy Script)
1899− propJSON (Proxy :: Proxy ScriptLanguage)
1900− propJSON (Proxy :: Proxy ScriptInline)
1901− propJSON (Proxy :: Proxy ScriptId)
1902− propJSON (Proxy :: Proxy ScriptParams)
1903− propJSON (Proxy :: Proxy CacheName)
1904− propJSON (Proxy :: Proxy CacheKey)
1905− propJSON (Proxy :: Proxy Existence)
1906− propJSON (Proxy :: Proxy CutoffFrequency)
1907− propJSON (Proxy :: Proxy Analyzer)
1908− propJSON (Proxy :: Proxy MaxExpansions)
1909− propJSON (Proxy :: Proxy Lenient)
1910− propJSON (Proxy :: Proxy Tiebreaker)
1911− propJSON (Proxy :: Proxy Boost)
1912− propJSON (Proxy :: Proxy BoostTerms)
1913− propJSON (Proxy :: Proxy MinimumMatch)
1914− propJSON (Proxy :: Proxy DisableCoord)
1915− propJSON (Proxy :: Proxy IgnoreTermFrequency)
1916− propJSON (Proxy :: Proxy MinimumTermFrequency)
1917− propJSON (Proxy :: Proxy MaxQueryTerms)
1918− propJSON (Proxy :: Proxy Fuzziness)
1919− propJSON (Proxy :: Proxy PrefixLength)
1920− propJSON (Proxy :: Proxy TypeName)
1921− propJSON (Proxy :: Proxy PercentMatch)
1922− propJSON (Proxy :: Proxy StopWord)
1923− propJSON (Proxy :: Proxy QueryPath)
1924− propJSON (Proxy :: Proxy AllowLeadingWildcard)
1925− propJSON (Proxy :: Proxy LowercaseExpanded)
1926− propJSON (Proxy :: Proxy EnablePositionIncrements)
1927− propJSON (Proxy :: Proxy AnalyzeWildcard)
1928− propJSON (Proxy :: Proxy GeneratePhraseQueries)
1929− propJSON (Proxy :: Proxy Locale)
1930− propJSON (Proxy :: Proxy MaxWordLength)
1931− propJSON (Proxy :: Proxy MinWordLength)
1932− propJSON (Proxy :: Proxy PhraseSlop)
1933− propJSON (Proxy :: Proxy MinDocFrequency)
1934− propJSON (Proxy :: Proxy MaxDocFrequency)
1935− propJSON (Proxy :: Proxy Filter)
1936− propJSON (Proxy :: Proxy Query)
1937− propJSON (Proxy :: Proxy SimpleQueryStringQuery)
1938− propJSON (Proxy :: Proxy FieldOrFields)
1939− propJSON (Proxy :: Proxy SimpleQueryFlag)
1940− propJSON (Proxy :: Proxy RegexpQuery)
1941− propJSON (Proxy :: Proxy QueryStringQuery)
1942− propJSON (Proxy :: Proxy RangeQuery)
1943− propJSON (Proxy :: Proxy PrefixQuery)
1944− propJSON (Proxy :: Proxy NestedQuery)
1945− propJSON (Proxy :: Proxy MoreLikeThisFieldQuery)
1946− propJSON (Proxy :: Proxy MoreLikeThisQuery)
1947− propJSON (Proxy :: Proxy IndicesQuery)
1948− propJSON (Proxy :: Proxy HasParentQuery)
1949− propJSON (Proxy :: Proxy HasChildQuery)
1950− propJSON (Proxy :: Proxy FuzzyQuery)
1951− propJSON (Proxy :: Proxy FuzzyLikeFieldQuery)
1952− propJSON (Proxy :: Proxy FuzzyLikeThisQuery)
1953− propJSON (Proxy :: Proxy FunctionScoreQuery)
1954− propJSON (Proxy :: Proxy BoostMode)
1955− propJSON (Proxy :: Proxy ScoreMode)
1956− propJSON (Proxy :: Proxy ComponentFunctionScoreFunction)
1957− propJSON (Proxy :: Proxy FieldValueFactor)
1958− propJSON (Proxy :: Proxy FactorModifier)
1959− propJSON (Proxy :: Proxy DisMaxQuery)
1960− propJSON (Proxy :: Proxy CommonTermsQuery)
1961− propJSON (Proxy :: Proxy CommonMinimumMatch)
1962− propJSON (Proxy :: Proxy BoostingQuery)
1963− propJSON (Proxy :: Proxy BoolQuery)
1964− propJSON (Proxy :: Proxy MatchQuery)
1965− propJSON (Proxy :: Proxy MultiMatchQueryType)
1966− propJSON (Proxy :: Proxy BooleanOperator)
1967− propJSON (Proxy :: Proxy ZeroTermsQuery)
1968− propJSON (Proxy :: Proxy MatchQueryType)
1969− propJSON (Proxy :: Proxy AliasRouting)
1970− propJSON (Proxy :: Proxy IndexAliasCreate)
1971− propJSON (Proxy :: Proxy SearchAliasRouting)
1972− propJSON (Proxy :: Proxy ScoreType)
1973− propJSON (Proxy :: Proxy Distance)
1974− propJSON (Proxy :: Proxy DistanceUnit)
1975− propJSON (Proxy :: Proxy DistanceType)
1976− propJSON (Proxy :: Proxy OptimizeBbox)
1977− propJSON (Proxy :: Proxy GeoBoundingBoxConstraint)
1978− propJSON (Proxy :: Proxy GeoFilterType)
1979− propJSON (Proxy :: Proxy GeoBoundingBox)
1980− propJSON (Proxy :: Proxy LatLon)
1981− propJSON (Proxy :: Proxy RangeExecution)
1982− prop "RegexpFlags FromJSON/ToJSON roundtrips, removing dups " $ \rfs ->
1983− let expected = case rfs of
1984− SomeRegexpFlags fs -> SomeRegexpFlags (NE.fromList (nub (NE.toList fs)))
1985− x -> x
1986− in parseEither parseJSON (toJSON rfs) === Right expected
1987− propJSON (Proxy :: Proxy BoolMatch)
1988− propJSON (Proxy :: Proxy Term)
1989− propJSON (Proxy :: Proxy MultiMatchQuery)
1990− propJSON (Proxy :: Proxy IndexSettings)
1991− propJSON (Proxy :: Proxy CompoundFormat)
1992− propJSON (Proxy :: Proxy TemplateQueryInline)
1993− propJSON (Proxy :: Proxy Suggest)
1994− propJSON (Proxy :: Proxy DirectGenerators)
1995− propJSON (Proxy :: Proxy DirectGeneratorSuggestModeTypes)
1996−
1997− describe "Approximate isomorphism JSON instances" $ do
1998− propApproxJSON (Proxy :: Proxy UpdatableIndexSetting')
1999− propApproxJSON (Proxy :: Proxy ReplicaCount)
2000− propApproxJSON (Proxy :: Proxy ReplicaBounds)
2001− propApproxJSON (Proxy :: Proxy Bytes)
2002− propApproxJSON (Proxy :: Proxy AllocationPolicy)
2003− propApproxJSON (Proxy :: Proxy InitialShardCount)
2004− propApproxJSON (Proxy :: Proxy FSType)