1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
{-# LANGUAGE OverloadedStrings #-}
module GitHub.ReleasesSpec where
import qualified GitHub
import GitHub.Auth (Auth (..))
import GitHub.Endpoints.Repos.Releases
(Release (..), latestReleaseR, releaseByTagNameR, releaseR, releasesR)
import GitHub.Request (executeRequest)
import Data.Either.Compat (isRight)
import Data.Proxy (Proxy (..))
import Data.String (fromString)
import System.Environment (lookupEnv)
import Test.Hspec
(Spec, describe, it, pendingWith, shouldBe, shouldSatisfy)
import qualified Data.Vector as V
fromRightS :: Show a => Either a b -> b
fromRightS (Right b) = b
fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a
withAuth :: (Auth -> IO ()) -> IO ()
withAuth action = do
mtoken <- lookupEnv "GITHUB_TOKEN"
case mtoken of
Nothing -> pendingWith "no GITHUB_TOKEN"
Just token -> action (OAuth $ fromString token)
spec :: Spec
spec = do
let v154Id = GitHub.mkId (Proxy :: Proxy Release) 5254449
v154Text = "v1.5.4"
describe "releasesR" $ do
it "works" $ withAuth $ \auth -> do
rs <- executeRequest auth $ releasesR "calleerlandsson" "pick" GitHub.FetchAll
rs `shouldSatisfy` isRight
V.length (fromRightS rs) `shouldSatisfy` (> 14)
describe "releaseR" $ do
it "works" $ withAuth $ \auth -> do
rs <- executeRequest auth $ releaseR "calleerlandsson" "pick" v154Id
rs `shouldSatisfy` isRight
releaseTagName (fromRightS rs)`shouldBe` v154Text
describe "latestReleaseR" $ do
it "works" $ withAuth $ \auth -> do
rs <- executeRequest auth $ latestReleaseR "calleerlandsson" "pick"
rs `shouldSatisfy` isRight
describe "releaseByTagNameR" $ do
it "works" $ withAuth $ \auth -> do
rs <- executeRequest auth $ releaseByTagNameR "calleerlandsson" "pick" v154Text
rs `shouldSatisfy` isRight
releaseId (fromRightS rs)`shouldBe` v154Id
|