main.hs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. {-# LANGUAGE EmptyDataDecls #-}
  2. {-# LANGUAGE ExistentialQuantification #-}
  3. {-# LANGUAGE FlexibleInstances #-}
  4. {-# LANGUAGE MultiParamTypeClasses #-}
  5. {-# LANGUAGE QuasiQuotes #-}
  6. {-# LANGUAGE TemplateHaskell #-}
  7. {-# LANGUAGE TypeFamilies #-}
  8. {-# LANGUAGE UndecidableInstances #-}
  9. {-# OPTIONS_GHC -Wno-unused-top-binds #-}
  10. import qualified Data.ByteString as BS
  11. import Data.IntMap (IntMap)
  12. import qualified Data.Text as T
  13. import Data.Time
  14. import Database.MongoDB (runCommand1)
  15. import Text.Blaze.Html
  16. import Test.QuickCheck
  17. -- FIXME: should this be added? (RawMongoHelpers module wasn't used)
  18. -- import qualified RawMongoHelpers
  19. import MongoInit
  20. -- These tests are noops with the NoSQL flags set.
  21. --
  22. -- import qualified CompositeTest
  23. -- import qualified CustomPrimaryKeyReferenceTest
  24. -- import qualified InsertDuplicateUpdate
  25. -- import qualified PersistUniqueTest
  26. -- import qualified PrimaryTest
  27. -- import qualified UniqueTest
  28. -- import qualified MigrationColumnLengthTest
  29. -- import qualified EquivalentTypeTest
  30. -- These modules were quite complicated. Instead of fully extracting the
  31. -- relevant common functionality, I just copied and de-CPPed manually.
  32. import qualified EmbedTestMongo
  33. -- These are done.
  34. import qualified CustomPersistFieldTest
  35. import qualified DataTypeTest
  36. import qualified EmbedOrderTest
  37. import qualified EmptyEntityTest
  38. import qualified HtmlTest
  39. import qualified LargeNumberTest
  40. import qualified MaxLenTest
  41. import qualified MigrationOnlyTest
  42. import qualified PersistentTest
  43. import qualified Recursive
  44. import qualified RenameTest
  45. import qualified SumTypeTest
  46. import qualified UpsertTest
  47. type Tuple = (,)
  48. dbNoCleanup :: Action IO () -> Assertion
  49. dbNoCleanup = db' (pure ())
  50. -- FIXME: This isn't actually used?
  51. share [mkPersist persistSettings, mkMigrate "htmlMigrate"] [persistLowerCase|
  52. HtmlTable
  53. html Html
  54. deriving
  55. |]
  56. mkPersist persistSettings [persistUpperCase|
  57. DataTypeTable no-json
  58. text Text
  59. textMaxLen Text maxlen=100
  60. bytes ByteString
  61. bytesTextTuple (Tuple ByteString Text)
  62. bytesMaxLen ByteString maxlen=100
  63. int Int
  64. intList [Int]
  65. intMap (IntMap Int)
  66. double Double
  67. bool Bool
  68. day Day
  69. utc UTCTime
  70. |]
  71. instance Arbitrary DataTypeTable where
  72. arbitrary = DataTypeTable
  73. <$> arbText -- text
  74. <*> (T.take 100 <$> arbText) -- textManLen
  75. <*> arbitrary -- bytes
  76. <*> liftA2 (,) arbitrary arbText -- bytesTextTuple
  77. <*> (BS.take 100 <$> arbitrary) -- bytesMaxLen
  78. <*> arbitrary -- int
  79. <*> arbitrary -- intList
  80. <*> arbitrary -- intMap
  81. <*> arbitrary -- double
  82. <*> arbitrary -- bool
  83. <*> arbitrary -- day
  84. <*> (truncateUTCTime =<< arbitrary) -- utc
  85. mkPersist persistSettings [persistUpperCase|
  86. EmptyEntity
  87. |]
  88. main :: IO ()
  89. main = do
  90. hspec $ afterAll dropDatabase $ do
  91. xdescribe "This test is failing for Mongo by only embedding the first thing." $ do
  92. RenameTest.specsWith (db' RenameTest.cleanDB)
  93. DataTypeTest.specsWith
  94. dbNoCleanup
  95. Nothing
  96. [ TestFn "Text" dataTypeTableText
  97. , TestFn "Text" dataTypeTableTextMaxLen
  98. , TestFn "Bytes" dataTypeTableBytes
  99. , TestFn "Bytes" dataTypeTableBytesTextTuple
  100. , TestFn "Bytes" dataTypeTableBytesMaxLen
  101. , TestFn "Int" dataTypeTableInt
  102. , TestFn "Int" dataTypeTableIntList
  103. , TestFn "Int" dataTypeTableIntMap
  104. , TestFn "Double" dataTypeTableDouble
  105. , TestFn "Bool" dataTypeTableBool
  106. , TestFn "Day" dataTypeTableDay
  107. ]
  108. []
  109. dataTypeTableDouble
  110. HtmlTest.specsWith (db' HtmlTest.cleanDB) Nothing
  111. EmbedTestMongo.specs
  112. EmbedOrderTest.specsWith (db' EmbedOrderTest.cleanDB)
  113. LargeNumberTest.specsWith
  114. (db' (deleteWhere ([] :: [Filter (LargeNumberTest.NumberGeneric backend)])))
  115. MaxLenTest.specsWith dbNoCleanup
  116. Recursive.specsWith (db' Recursive.cleanup)
  117. SumTypeTest.specsWith (dbNoCleanup) Nothing
  118. MigrationOnlyTest.specsWith
  119. dbNoCleanup
  120. Nothing
  121. PersistentTest.specsWith (db' PersistentTest.cleanDB)
  122. -- TODO: The upsert tests are currently failing. Find out why and fix
  123. -- them.
  124. xdescribe "UpsertTest is currently failing for Mongo due to differing behavior" $ do
  125. UpsertTest.specsWith
  126. (db' PersistentTest.cleanDB)
  127. UpsertTest.AssumeNullIsZero
  128. UpsertTest.UpsertGenerateNewKey
  129. EmptyEntityTest.specsWith
  130. (db' EmptyEntityTest.cleanDB)
  131. Nothing
  132. CustomPersistFieldTest.specsWith
  133. dbNoCleanup
  134. -- FIXME: should this be added? (RawMongoHelpers module wasn't used)
  135. -- RawMongoHelpers.specs
  136. where
  137. dropDatabase () = dbNoCleanup (void (runCommand1 $ T.pack "dropDatabase()"))