graphql-engine/server/src-test/Hasura/Server/Migrate/VersionSpec.hs
Samir Talwar 5f38743f29 server: Encapsulate catalog versions in their own type.
This came about as I tried to add an instance over catalog versions and
found they were just simple integers most of the time (and in one case,
a float).

I think this change also clarifies how catalog versions work.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4864
GitOrigin-RevId: a6b7db86de564b71a8c2b602bee6a456b8e20d63
2022-06-29 08:19:33 +00:00

41 lines
1.5 KiB
Haskell

module Hasura.Server.Migrate.VersionSpec (spec) where
import Data.Either (isLeft)
import Hasura.Prelude
import Hasura.Server.Migrate.Version
import Hedgehog.Gen qualified as Gen
import Hedgehog.Range qualified as Range
import Test.Hspec
import Test.Hspec.Hedgehog
spec :: Spec
spec =
describe "a catalog version" do
it "can be read from an integer" $ hedgehog do
expected :: Int <- forAll $ Gen.integral (Range.constant 0 maxBound)
let input = show expected
let version :: Either String CatalogVersion = readEither input
version === Right (CatalogVersion expected)
it "cannot be read from a negative integer" $ hedgehog do
expected :: Int <- forAll $ Gen.integral (Range.constant minBound (-1))
let input = show expected
let version :: Either String CatalogVersion = readEither input
assert $ isLeft version
it "can read the number 0.8, for legacy reasons" do
let version :: Either String CatalogVersion = readEither "0.8"
in version `shouldBe` Right CatalogVersion08
it "cannot read the number 0.8 in another form" do
let version :: Either String CatalogVersion = readEither "8e-1"
in version `shouldSatisfy` isLeft
it "cannot read any other non-integral number" $ hedgehog do
expected <-
forAll $
Gen.filter (/= 0.8) $ Gen.float (Range.constantFrom 0 (-1e6) 1e6)
let input = show expected
let version :: Either String CatalogVersion = readEither input
assert $ isLeft version