Skip to content

Commit

Permalink
Add integration test for vacuum (swagger linter).
Browse files Browse the repository at this point in the history
  • Loading branch information
fisx committed Oct 22, 2024
1 parent 8cd5046 commit 3983741
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions integration/test/Test/Swagger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import qualified API.Brig as BrigP
import qualified Data.Set as Set
import Data.String.Conversions
import GHC.Stack
import System.Exit
import System.Process
import Testlib.Assertions
import Testlib.Prelude
import UnliftIO.Directory
import UnliftIO.Temporary

existingVersions :: Set Int
existingVersions = Set.fromList [0, 1, 2, 3, 4, 5, 6, 7]
Expand Down Expand Up @@ -80,3 +84,17 @@ testSwaggerToc = do

html :: String
html = "<html><head></head><body><h2>please pick an api version</h2><a href=\"/v0/api/swagger-ui/\">/v0/api/swagger-ui/</a><br><a href=\"/v1/api/swagger-ui/\">/v1/api/swagger-ui/</a><br><a href=\"/v2/api/swagger-ui/\">/v2/api/swagger-ui/</a><br><a href=\"/v3/api/swagger-ui/\">/v3/api/swagger-ui/</a><br><a href=\"/v4/api/swagger-ui/\">/v4/api/swagger-ui/</a><br><a href=\"/v5/api/swagger-ui/\">/v5/api/swagger-ui/</a><br><a href=\"/v6/api/swagger-ui/\">/v6/api/swagger-ui/</a><br><a href=\"/v7/api/swagger-ui/\">/v7/api/swagger-ui/</a><br></body>"

-- | This runs the swagger linter [vacuum](https://quobix.com/vacuum/). There is also a make
-- rule that does this, for convenience in your develop flow. In order to run vacuum on CI, we need a running brig (or at least but running this this test case
-- makes it easier to do this in the integration test job on our CI. vacuum
testSwaggerLint :: (HasCallStack) => App ()
testSwaggerLint = do
withSystemTempDirectory "testSwaggerLint-XXX.swagger.json" $ \swaggerFile ->
withCurrentDirectory swaggerFile $ do
let url = "http://localhost:8082/v" <> show (maximum existingVersions) <> "/api/swagger.json"
cmd = shell ("curl " <> url <> " > swagger.json && vacuum lint swagger.json 2>&1")
outcome@(exitCode, _out, _err) <- liftIO $ readCreateProcessWithExitCode cmd ""
case exitCode of
ExitSuccess -> pure ()
_ -> error (show outcome)

0 comments on commit 3983741

Please sign in to comment.