Skip to content

Commit

Permalink
fake fileserver for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed May 21, 2024
1 parent 162b0e4 commit 61e3412
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions src/swarm-tournament/Swarm/Web/Tournament.hs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ doLoginResponse authStorage refererUrl userAlias = do

-- * Web app declaration

app :: AppData -> Application
app appData = Servant.serveWithContext (Proxy :: Proxy ToplevelAPI) context server
app :: Bool -> AppData -> Application
app unitTestFileserver appData =
Servant.serveWithContext (Proxy :: Proxy ToplevelAPI) context $
server unitTestFileserver
where
size100kB = 100_000 :: Int64

Expand All @@ -346,13 +348,23 @@ app appData = Servant.serveWithContext (Proxy :: Proxy ToplevelAPI) context serv
(developmentMode appData)
context = thisAuthHandler :. multipartOpts :. EmptyContext

server :: Server ToplevelAPI
server =
server :: Bool -> Server ToplevelAPI
server fakeFileserverForUnitTest =
mkApp appData
:<|> Tagged serveDocs
:<|> serveDirectoryWith
(defaultFileServerSettings "tournament/web")
:<|> fileserver
where
fileserver =
if fakeFileserverForUnitTest
then
serveDirectoryEmbedded
[ ("/list-games.html", "Hello World!")
, ("/list-solutions.html", "Hello World!")
]
else
serveDirectoryWith
(defaultFileServerSettings "tournament/web")

serveDocs _ resp =
resp $ responseLBS ok200 [htmlType] tournamentsApiHtml
htmlType = ("Content-Type", "text/html")
Expand All @@ -361,6 +373,6 @@ webMain ::
AppData ->
Warp.Port ->
IO ()
webMain appData port = Warp.runSettings settings $ app appData
webMain appData port = Warp.runSettings settings $ app False appData
where
settings = Warp.setPort port Warp.defaultSettings
2 changes: 1 addition & 1 deletion test/tournament-host/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,4 @@ uploadForm appData urlPath form =
]
assertEqual assertionMsg ok200 $ responseStatus resp
where
tournamentApp = Tournament.app appData
tournamentApp = Tournament.app True appData

0 comments on commit 61e3412

Please sign in to comment.