Skip to content

Commit

Permalink
Make tests not depend on order of HashSet items
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-leapyear committed Feb 5, 2022
1 parent 2460bef commit 94af153
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/Snap/Util/CORS/Tests.hs
Expand Up @@ -8,6 +8,9 @@ module Snap.Util.CORS.Tests (tests) where
import Data.ByteString.Char8 (ByteString)
import Data.CaseInsensitive (CI (..))
import qualified Data.HashSet as HashSet
import qualified Data.Set as Set
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Snap.Core (Method (..), getHeader, Response(..))
import Snap.Test (RequestBuilder, runHandler, setHeader, setRequestType, RequestType(..), setRequestPath)
import Snap.Util.CORS (applyCORS,CORSOptions(..),defaultOptions,HashableMethod(..))
Expand Down Expand Up @@ -97,7 +100,12 @@ checkExposeHeaders :: Maybe ByteString -> Response -> Assertion
checkExposeHeaders = checkHeader "Access-Control-Expose-Headers"

checkAllowHeaders :: Maybe ByteString -> Response -> Assertion
checkAllowHeaders = checkHeader "Access-Control-Allow-Headers"
checkAllowHeaders v r =
assertEqual "Header Access-Control-Allow-Headers"
(getSet <$> v)
(getSet <$> getHeader "Access-Control-Allow-Headers" r)
where
getSet = Set.fromList . Text.splitOn ", " . Text.decodeUtf8

checkAllowMethods :: Maybe ByteString -> Response -> Assertion
checkAllowMethods = checkHeader "Access-Control-Allow-Methods"
Expand Down

0 comments on commit 94af153

Please sign in to comment.