graphql-engine/server/lib/ekg-prometheus/test/Validation.hs
kodiakhq[bot] d4e368324d chore(tooling): import ekg-prometheus into the monorepo
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9526
Co-authored-by: awjchen <13142944+awjchen@users.noreply.github.com>
Co-authored-by: paritosh-08 <85472423+paritosh-08@users.noreply.github.com>
GitOrigin-RevId: 131739ab8e68165453fd47d1eafcc7957ec6f411
2023-06-27 18:37:11 +00:00

45 lines
1.3 KiB
Haskell

{-# LANGUAGE OverloadedStrings #-}
module Validation
( tests,
)
where
import System.Metrics.Prometheus.Validation
( isValidHelpText,
isValidLabelValue,
)
import Test.Hspec
( Spec,
describe,
it,
shouldBe,
)
-- | Basic tests of the valdiation functions.
tests :: Spec
tests =
describe "Validation functions" $ do
describe "`isValidHelpText`" $ do
it "accepts empty strings" $
isValidHelpText "" `shouldBe` True
it "accepts escaped backslashes and newlines" $
isValidHelpText "\\\\,\\n" `shouldBe` True
it "rejects unescaped backslashes" $ do
isValidHelpText "\\" `shouldBe` False
isValidHelpText "\\t" `shouldBe` False
it "rejects unescaped newlines" $
isValidHelpText "\n" `shouldBe` False
describe "`isValidLabelValue`" $ do
it "accepts empty strings" $
isValidLabelValue "" `shouldBe` True
it "accepts escaped backslashes, newlines, and double-quotes" $
isValidLabelValue "\\\\,\\n,\\\"" `shouldBe` True
it "rejects unescaped backslashes" $ do
isValidLabelValue "\\" `shouldBe` False
isValidLabelValue "\\t" `shouldBe` False
it "rejects unescaped newlines" $
isValidLabelValue "\n" `shouldBe` False
it "rejects unescaped double-quotes" $
isValidLabelValue "\"" `shouldBe` False