Skip to content

Commit 36de147

Browse files
committed
Merge pull request haskell-github#187 from phadej/search-tests-no-network
Don't require network for search tests
2 parents 8354c88 + a808958 commit 36de147

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

spec/GitHub/SearchSpec.hs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@ module GitHub.SearchSpec where
55
import Prelude ()
66
import Prelude.Compat
77

8-
import Data.Aeson.Compat (eitherDecodeStrict)
9-
import Data.FileEmbed (embedFile)
10-
import Test.Hspec (Spec, describe, it, shouldBe)
8+
import Data.Aeson.Compat (eitherDecodeStrict)
9+
import Data.FileEmbed (embedFile)
10+
import Data.Proxy (Proxy (..))
11+
import Data.String (fromString)
12+
import System.Environment (lookupEnv)
13+
import Test.Hspec (Spec, describe, it, pendingWith, shouldBe)
1114

1215
import qualified Data.Vector as V
1316

14-
import GitHub.Data.Id (Id (..))
15-
import GitHub.Data.Issues (Issue (..))
16-
import GitHub.Endpoints.Search (SearchResult (..), searchIssues)
17+
import GitHub.Data (Auth (..), Issue (..), mkId)
18+
import GitHub.Endpoints.Search (SearchResult (..), searchIssues')
1719

1820
fromRightS :: Show a => Either a b -> b
1921
fromRightS (Right b) = b
2022
fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a
2123

24+
withAuth :: (Auth -> IO ()) -> IO ()
25+
withAuth action = do
26+
mtoken <- lookupEnv "GITHUB_TOKEN"
27+
case mtoken of
28+
Nothing -> pendingWith "no GITHUB_TOKEN"
29+
Just token -> action (OAuth $ fromString token)
30+
2231
spec :: Spec
2332
spec = do
2433
describe "searchIssues" $ do
@@ -30,19 +39,19 @@ spec = do
3039
V.length issues `shouldBe` 2
3140

3241
let issue1 = issues V.! 0
33-
issueId issue1 `shouldBe` Id 123898390
42+
issueId issue1 `shouldBe` mkId (Proxy :: Proxy Issue) 123898390
3443
issueNumber issue1 `shouldBe` 130
3544
issueTitle issue1 `shouldBe` "Make test runner more robust"
3645
issueState issue1 `shouldBe` "closed"
3746

3847
let issue2 = issues V.! 1
39-
issueId issue2 `shouldBe` Id 119694665
48+
issueId issue2 `shouldBe` mkId (Proxy :: Proxy Issue) 119694665
4049
issueNumber issue2 `shouldBe` 127
4150
issueTitle issue2 `shouldBe` "Decouple request creation from execution"
4251
issueState issue2 `shouldBe` "open"
4352

44-
it "performs an issue search via the API" $ do
53+
it "performs an issue search via the API" $ withAuth $ \auth -> do
4554
let query = "Decouple in:title repo:phadej/github created:<=2015-12-01"
46-
issues <- searchResultResults . fromRightS <$> searchIssues query
55+
issues <- searchResultResults . fromRightS <$> searchIssues' (Just auth) query
4756
length issues `shouldBe` 1
48-
issueId (V.head issues) `shouldBe` Id 119694665
57+
issueId (V.head issues) `shouldBe` mkId (Proxy :: Proxy Issue) 119694665

0 commit comments

Comments
 (0)