Skip to content

Commit 9f938a9

Browse files
committed
Include marshalling test for Vector a as well
1 parent f9fc3fe commit 9f938a9

File tree

1 file changed

+25
-15
lines changed
  • beam-postgres/test/Database/Beam/Postgres/Test

1 file changed

+25
-15
lines changed

beam-postgres/test/Database/Beam/Postgres/Test/Marshal.hs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,28 +166,35 @@ marshalTest' cmp gen postgresConn =
166166
assertBool "Hedgehog test failed" passes
167167

168168

169-
-- Ensure that `Maybe (Vector Text)` can be marshalled correctly (See issue 692).
169+
-- Ensure that both `Vector Text` and `Maybe (Vector Text)` can be
170+
-- marshalled correctly (see issue 692).
170171
--
171172
-- At this time, the postgres migration backend can't create columns of arrays,
172173
-- and hence this test does not use `marshalTest`.
173174
marshalTest692 :: IO ByteString -> TestTree
174175
marshalTest692 postgresConn =
175-
testCase "Can marshal Maybe (Vector Text) (#692)" $
176+
testCase "Can marshal Vector Text and Maybe (Vector Text) (#692)" $
176177
withTestPostgres ("db_marshal_maybe_vector_text_issue_692") postgresConn $ \conn -> do
177-
liftIO $ execute_ conn $ "CREATE TABLE mytable (\nmyid SERIAL PRIMARY KEY, mycolumn text[]\n);"
178+
liftIO $ execute_ conn $ "CREATE TABLE mytable (\nmyid SERIAL PRIMARY KEY, mycolumn text[], mynullablecolumn text[]\n);"
178179

179180
passes <- Hedgehog.check . Hedgehog.property $ do
180-
a <- Hedgehog.forAll (Gen.maybe (Vector.fromList <$> (Gen.list (Range.linear 0 10) textGen)))
181+
nullable <- Hedgehog.forAll (Gen.maybe (Vector.fromList <$> (Gen.list (Range.linear 0 10) textGen)))
182+
nonnull <- Hedgehog.forAll (Vector.fromList <$> (Gen.list (Range.linear 0 10) textGen))
181183

182-
[MkTbl692 rowId v] <-
183-
liftIO . runBeamPostgres conn $
184-
runInsertReturningList $ insert (_myTable myDB) $ insertExpressions [ MkTbl692 default_ (val_ a) ]
185-
v === a
184+
[MkTbl692 rowId v vnull] <-
185+
liftIO . runBeamPostgres conn
186+
$ runInsertReturningList
187+
$ insert (_myTable myDB)
188+
$ insertExpressions [ MkTbl692 default_ (val_ nonnull) (val_ nullable) ]
186189

187-
Just (MkTbl692 _ v') <-
188-
liftIO . runBeamPostgres conn $
189-
runSelectReturningOne (lookup_ (_myTable myDB) (Tbl692Key rowId))
190-
v' === a
190+
v === nonnull
191+
vnull === nullable
192+
193+
Just (MkTbl692 _ v' vnull') <-
194+
liftIO . runBeamPostgres conn
195+
$ runSelectReturningOne (lookup_ (_myTable myDB) (Tbl692Key rowId))
196+
v' === nonnull
197+
vnull' === nullable
191198

192199
assertBool "Hedgehog test failed" passes
193200
where
@@ -199,14 +206,17 @@ marshalTest692 postgresConn =
199206
modifyTableFields
200207
tableModification {
201208
myid = fieldNamed "myid",
202-
mycolumn = fieldNamed "mycolumn"
209+
mycolumn = fieldNamed "mycolumn",
210+
mynullablecolumn = fieldNamed "mynullablecolumn"
203211
}
204212
}
205213

206214
data Tbl692 f
207215
= MkTbl692
208-
{ myid :: C f (SqlSerial Int32)
209-
, mycolumn :: C f (Maybe (Vector.Vector T.Text)) }
216+
{ myid :: C f (SqlSerial Int32)
217+
, mycolumn :: C f (Vector.Vector T.Text)
218+
, mynullablecolumn :: C f (Maybe (Vector.Vector T.Text))
219+
}
210220
deriving (Generic, Beamable)
211221

212222
deriving instance Show (Tbl692 Identity)

0 commit comments

Comments
 (0)