diff --git a/test/Unit/PgStructureSpec.hs b/test/Unit/PgStructureSpec.hs new file mode 100644 index 000000000..059283c69 --- /dev/null +++ b/test/Unit/PgStructureSpec.hs @@ -0,0 +1,23 @@ +module Unit.PgStructureSpec where + +import Test.Hspec +import PgStructure (Table(..), tables, Column(..), columns) + +import Database.HDBC (quickQuery) +import SpecHelper(dbWithSchema) + +spec :: Spec +spec = around dbWithSchema $ beforeWith setRole $ do + describe "tables" $ + it "shows all the tables" $ \conn -> do + ts <- tables "1" conn + map tableName ts `shouldBe` ["auto_incrementing_pk","compound_pk", + "has_fk","items","menagerie","no_pk", "simple_pk"] + + describe "columns" $ + it "responds with each column for the table" $ \conn -> do + cs <- columns "1" "auto_incrementing_pk" conn + map colName cs `shouldBe` ["id","nullable_string","non_nullable_string", + "inserted_at"] + + where setRole = \conn -> quickQuery conn "set role dbapi_test" [] >> return conn