mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-21 14:31:55 +03:00
dca8559703
write a proper parser according to the RFC https://tools.ietf.org/html/rfc7234#section-5.2
29 lines
1.0 KiB
Haskell
29 lines
1.0 KiB
Haskell
module Data.Parser.CacheControlSpec (spec) where
|
|
|
|
import Hasura.Prelude
|
|
|
|
import qualified Data.Parser.CacheControl as CCP
|
|
|
|
import Test.Hspec
|
|
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
describe "successfully parse cache-control header" $ do
|
|
it "parses max-age=5" $ do
|
|
let header = "public, must-revalidate, max-age=5, no-transform"
|
|
CCP.parseMaxAge @Integer header `shouldBe` Right 5
|
|
|
|
it "parses s-maxage=5" $ do
|
|
let header = "public, must-revalidate, s-maxage=5, no-transform"
|
|
CCP.parseMaxAge @Integer header `shouldBe` Right 5
|
|
|
|
describe "parse cache-control header fails" $ do
|
|
it "doesn't have max-age; fails parsing max-age" $ do
|
|
let header = "public, must-revalidate, no-transform"
|
|
CCP.parseMaxAge @Integer header `shouldBe` Left "could not find max-age/s-maxage"
|
|
|
|
it "max-age value is wrong; fails parsing max-age" $ do
|
|
let header = "public, max-age=\"abcd\" must-revalidate, no-transform"
|
|
CCP.parseMaxAge @Integer header `shouldBe` Left "could not find max-age/s-maxage"
|