Last active
June 14, 2017 20:51
-
-
Save jkachmar/263b69a8d49dcd1c3f1b844396801982 to your computer and use it in GitHub Desktop.
Tasty Scaffold
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Handler.AuthTest where | |
| -- * Prelude. | |
| import ClassyPrelude | |
| -- * Database imports. | |
| import Database.Persist | |
| import Database.Persist.Sql | |
| -- * Testing imports. | |
| import Test.Tasty | |
| import Test.Tasty.Hspec | |
| -- * Project imports. | |
| import Foundation | |
| -- import Logger | |
| import Model | |
| -------------------------------------------------------------------------------- | |
| -- | Scaffold a testing database and environment. | |
| scaffold :: IO Config | |
| scaffold = do | |
| logger <- makeLogger Testing | |
| pool <- makePool Testing logger | |
| pure $ Config pool (undefined) logger | |
| -- | Teardown the testing database and environment. | |
| teardown :: Config -> IO () | |
| teardown cfg = flip runReaderT cfg $ runDB $ do | |
| tables <- getTables | |
| sqlBackend <- ask | |
| let escapedTables = map (connEscapeName sqlBackend . DBName) tables | |
| query = "TRUNCATE TABLE " ++ intercalate ", " escapedTables | |
| rawExecute query [] | |
| -- | Get a list of all tables in the connected database. | |
| getTables :: MonadIO m => SqlPersistT m [Text] | |
| getTables = do | |
| let query = "SELECT table_name\ | |
| \FROM information_schema.tables\ | |
| \WHERE table_schema = 'public';" | |
| tables <- rawSql query [] | |
| pure $ map unSingle tables | |
| -------------------------------------------------------------------------------- | |
| -- | Hspec test. | |
| prelude :: Spec | |
| prelude = do | |
| describe "Prelude.head" $ do | |
| it "returns the first element of a list" $ do | |
| 23 `shouldBe` (23 :: Int) | |
| test_all :: IO TestTree | |
| test_all = do | |
| testSpec "Run my goddamn tests" prelude |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# | |
| OPTIONS_GHC -F | |
| -pgmF tasty-discover | |
| -optF --tree-display | |
| #-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment