Skip to content

Commit 8af91e2

Browse files
committed
Merge pull request #508 from begriffs/test-plain-build
Test that binary builds, not just that suite passes
2 parents 4cd2475 + cf176c4 commit 8af91e2

File tree

6 files changed

+34
-33
lines changed

6 files changed

+34
-33
lines changed

circle.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ dependencies:
99
- createdb -O postgrest_test -U ubuntu postgrest_test
1010
override:
1111
- stack setup
12+
- rm -fr $(stack path --dist-dir) $(stack path --local-install-root)
1213
- stack install hlint packdeps cabal-install
14+
- stack build
1315
- stack build --test --no-run-tests
1416

1517
test:

postgrest.cabal

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ executable postgrest
2626
default-extensions: OverloadedStrings, ScopedTypeVariables, QuasiQuotes
2727
ghc-options: -threaded -rtsopts -with-rtsopts=-N
2828
default-language: Haskell2010
29-
build-depends: aeson >= 0.8 && < 0.10
29+
build-depends: aeson (>= 0.8 && < 0.10) || (>= 0.11 && < 0.12)
3030
, base >= 4.8 && < 5
3131
, bytestring
3232
, case-insensitive
@@ -138,14 +138,14 @@ Test-Suite spec
138138
, Feature.DeleteSpec
139139
, Feature.InsertSpec
140140
, Feature.QuerySpec
141+
, Feature.QueryLimitedSpec
141142
, Feature.RangeSpec
142143
, Feature.StructureSpec
143144
, Paths_postgrest
144145
, PostgREST.App
145146
, PostgREST.Auth
146147
, PostgREST.Config
147148
, PostgREST.Error
148-
, PostgREST.Main
149149
, PostgREST.Middleware
150150
, PostgREST.Parsers
151151
, PostgREST.DbStructure

src/PostgREST/App.hs

+27-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{-# LANGUAGE TupleSections #-}
44
--module PostgREST.App where
55
module PostgREST.App (
6-
app
6+
postgrest
77
) where
88

99
import Control.Applicative
@@ -18,6 +18,9 @@ import Data.String.Conversions (cs)
1818
import Data.Text (Text, replace, strip)
1919
import Data.Tree
2020

21+
import qualified Hasql.Pool as P
22+
import qualified Hasql.Transaction as HT
23+
2124
import Text.Parsec.Error
2225
import Text.ParserCombinators.Parsec (parse)
2326

@@ -26,25 +29,26 @@ import Network.HTTP.Types.Header
2629
import Network.HTTP.Types.Status
2730
import Network.HTTP.Types.URI (parseSimpleQuery)
2831
import Network.Wai
32+
import Network.Wai.Middleware.RequestLogger (logStdout)
2933

3034
import Data.Aeson
3135
import Data.Aeson.Types (emptyArray)
3236
import Data.Monoid
37+
import Data.Time.Clock.POSIX (getPOSIXTime)
3338
import qualified Data.Vector as V
3439
import qualified Hasql.Transaction as H
3540

36-
import PostgREST.Config (AppConfig (..))
37-
import PostgREST.Parsers
38-
import PostgREST.DbStructure
39-
import PostgREST.RangeQuery
4041
import PostgREST.ApiRequest (ApiRequest(..), ContentType(..)
4142
, Action(..), Target(..)
4243
, PreferRepresentation (..)
4344
, userApiRequest)
44-
import PostgREST.Types
4545
import PostgREST.Auth (tokenJWT)
46-
import PostgREST.Error (errResponse)
47-
46+
import PostgREST.Config (AppConfig (..))
47+
import PostgREST.DbStructure
48+
import PostgREST.Error (errResponse, pgErrResponse)
49+
import PostgREST.Parsers
50+
import PostgREST.RangeQuery
51+
import PostgREST.Middleware
4852
import PostgREST.QueryBuilder ( callProc
4953
, addJoinConditions
5054
, sourceCTEName
@@ -55,9 +59,24 @@ import PostgREST.QueryBuilder ( callProc
5559
, createWriteStatement
5660
, ResultsWithCount
5761
)
62+
import PostgREST.Types
5863

5964
import Prelude
6065

66+
67+
postgrest :: AppConfig -> DbStructure -> P.Pool -> Application
68+
postgrest conf dbStructure pool =
69+
let middle = (if configQuiet conf then id else logStdout) . defaultMiddle in
70+
71+
middle $ \ req respond -> do
72+
time <- getPOSIXTime
73+
body <- strictRequestBody req
74+
75+
let handleReq = runWithClaims conf time (app dbStructure conf body) req
76+
resp <- either pgErrResponse id <$> P.use pool
77+
(HT.run handleReq HT.ReadCommitted HT.Write)
78+
respond resp
79+
6180
app :: DbStructure -> AppConfig -> RequestBody -> Request -> H.Transaction Response
6281
app dbStructure conf reqBody req =
6382
let

src/PostgREST/Main.hs

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE CPP #-}
22

3-
module PostgREST.Main where
3+
module Main where
44

55

66
import PostgREST.App
@@ -9,23 +9,16 @@ import PostgREST.Config (AppConfig (..),
99
prettyVersion,
1010
readOptions)
1111
import PostgREST.DbStructure
12-
import PostgREST.Error (pgErrResponse)
13-
import PostgREST.Middleware
14-
import PostgREST.Types (DbStructure)
1512

1613
import Control.Monad
1714
import Data.Monoid ((<>))
1815
import Data.String.Conversions (cs)
19-
import Data.Time.Clock.POSIX (getPOSIXTime)
2016
import qualified Hasql.Query as H
2117
import qualified Hasql.Session as H
22-
import qualified Hasql.Transaction as HT
2318
import qualified Hasql.Decoders as HD
2419
import qualified Hasql.Encoders as HE
2520
import qualified Hasql.Pool as P
26-
import Network.Wai
2721
import Network.Wai.Handler.Warp
28-
import Network.Wai.Middleware.RequestLogger (logStdout)
2922
import System.IO (BufferMode (..),
3023
hSetBuffering, stderr,
3124
stdin, stdout)
@@ -82,16 +75,3 @@ main = do
8275

8376
let dbStructure = either (error.show) id result
8477
runSettings appSettings $ postgrest conf dbStructure pool
85-
86-
postgrest :: AppConfig -> DbStructure -> P.Pool -> Application
87-
postgrest conf dbStructure pool =
88-
let middle = (if configQuiet conf then id else logStdout) . defaultMiddle in
89-
90-
middle $ \ req respond -> do
91-
time <- getPOSIXTime
92-
body <- strictRequestBody req
93-
94-
let handleReq = runWithClaims conf time (app dbStructure conf body) req
95-
resp <- either pgErrResponse id <$> P.use pool
96-
(HT.run handleReq HT.ReadCommitted HT.Write)
97-
respond resp

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: lts-5.0
1+
resolver: lts-5.5
22
extra-deps:
33
- Ranged-sets-0.3.0
44
- bytestring-tree-builder-0.2.5

test/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SpecHelper
66
import qualified Hasql.Pool as P
77

88
import PostgREST.DbStructure (getDbStructure)
9-
import PostgREST.Main (postgrest)
9+
import PostgREST.App (postgrest)
1010
import Data.String.Conversions (cs)
1111

1212
import qualified Feature.AuthSpec

0 commit comments

Comments
 (0)