Skip to content

Commit ffa6d6b

Browse files
committed
Make test runner more robust
1 parent c626d43 commit ffa6d6b

5 files changed

Lines changed: 71 additions & 6 deletions

File tree

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ before_cache:
1111
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
1212
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar
1313

14+
env:
15+
global:
16+
secure: "J522iO9HE8yIMwcbBBCXYiAJ0bZSzMjq9nue6oockCIZc3kSoF/IGhfBMns3KRrzMR7nD0IirpHB0jjSXIQLA+51SaWS8HG2+pI+U3qvCoeDIaB85Iyhk932GIymdySCH7ypw71AeuJTErvZ67TR3m+o98BBk8WgMCcLkGykWKA="
17+
1418
matrix:
1519
include:
1620
- env: CABALVER=1.18 GHCVER=7.8.4
@@ -73,7 +77,7 @@ script:
7377
- if [ -f configure.ac ]; then autoreconf -i; fi
7478
- cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging
7579
- cabal build # this builds all libraries and executables (including tests/benchmarks)
76-
- cabal test
80+
- cabal test --show-details=always
7781

7882
- if [ "$CABALVER" = "1.22" ]; then cabal check; fi
7983
- if [ "$CABALVER" = "1.22" ]; then cabal haddock; fi

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ No support? Not sure.
139139

140140
See `DetailedOwner` to know what data could be provided.
141141

142+
Test setup
143+
==========
144+
145+
To run integration part of tests, you'll need [github access token](https://github.com/settings/tokens/new)
146+
Token is needed, because unauthorised access is highly limited.
147+
It's enough to add only basic read access for public information.
148+
149+
With `travis encrypt --org --repo yournick/github "GITHUB_TOKEN=yourtoken"` command you get a secret,
150+
you can use in your travis setup to run the test-suite there.
142151

143152
Contributions
144153
=============

fixtures/user.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"login": "mike-burns",
3+
"id": 4550,
4+
"avatar_url": "https://avatars.githubusercontent.com/u/4550?v=3",
5+
"gravatar_id": "",
6+
"url": "https://api.github.com/users/mike-burns",
7+
"html_url": "https://github.com/mike-burns",
8+
"followers_url": "https://api.github.com/users/mike-burns/followers",
9+
"following_url": "https://api.github.com/users/mike-burns/following{/other_user}",
10+
"gists_url": "https://api.github.com/users/mike-burns/gists{/gist_id}",
11+
"starred_url": "https://api.github.com/users/mike-burns/starred{/owner}{/repo}",
12+
"subscriptions_url": "https://api.github.com/users/mike-burns/subscriptions",
13+
"organizations_url": "https://api.github.com/users/mike-burns/orgs",
14+
"repos_url": "https://api.github.com/users/mike-burns/repos",
15+
"events_url": "https://api.github.com/users/mike-burns/events{/privacy}",
16+
"received_events_url": "https://api.github.com/users/mike-burns/received_events",
17+
"type": "User",
18+
"site_admin": false,
19+
"name": "Mike Burns",
20+
"company": "thoughtbot",
21+
"blog": "http://mike-burns.com/",
22+
"location": "Stockholm, Sweden",
23+
"email": "mburns@thoughtbot.com",
24+
"hireable": true,
25+
"bio": null,
26+
"public_repos": 35,
27+
"public_gists": 32,
28+
"followers": 171,
29+
"following": 0,
30+
"created_at": "2008-04-03T17:54:24Z",
31+
"updated_at": "2015-10-02T16:53:25Z"
32+
}

github.cabal

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Library
181181
Build-depends: base >= 4.0 && < 5.0,
182182
time >=1.4 && <1.6,
183183
aeson >= 0.6.1.0,
184-
aeson-extra >= 0.2.0.0,
184+
aeson-extra >= 0.2.0.0 && <0.3,
185185
attoparsec >= 0.10.3.0,
186186
bytestring,
187187
case-insensitive >= 0.4.0.4,
@@ -210,9 +210,13 @@ test-suite github-test
210210
default-language: Haskell2010
211211
type: exitcode-stdio-1.0
212212
hs-source-dirs: spec
213+
other-modules:
214+
Github.UsersSpec
213215
main-is: Spec.hs
214216
build-depends: base >= 4.0 && < 5.0,
217+
aeson-extra >= 0.2.0.0 && <0.3,
215218
github,
219+
file-embed,
216220
hspec
217221

218222
ghc-options: -Wall -fno-warn-orphans

spec/Github/UsersSpec.hs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1+
{-# LANGUAGE TemplateHaskell #-}
12
module Github.UsersSpec where
23

3-
import Github.Users (userInfoFor)
4+
import Github.Auth (GithubAuth(..))
5+
import Github.Users (userInfoFor')
46
import Github.Data.Definitions (DetailedOwner(..))
57

6-
import Test.Hspec (it, describe, shouldBe, Spec)
8+
import Data.Aeson.Compat (eitherDecodeStrict)
9+
import Test.Hspec (it, describe, shouldBe, pendingWith, Spec)
10+
import System.Environment (lookupEnv)
11+
import Data.FileEmbed (embedFile)
712

813
fromRightS :: Show a => Either a b -> b
914
fromRightS (Right b) = b
1015
fromRightS (Left a) = error $ "Expected a Right and got a Left" ++ show a
1116

17+
withAuth :: (GithubAuth -> IO ()) -> IO ()
18+
withAuth action = do
19+
mtoken <- lookupEnv "GITHUB_TOKEN"
20+
case mtoken of
21+
Nothing -> pendingWith "no GITHUB_TOKEN"
22+
Just token -> action (GithubOAuth token)
23+
1224
spec :: Spec
1325
spec =
1426
describe "userInfoFor" $ do
15-
it "returns information about the user" $ do
16-
userInfo <- userInfoFor "mike-burns"
27+
it "decodes user json" $ do
28+
let userInfo = eitherDecodeStrict $(embedFile "fixtures/user.json") :: Either String DetailedOwner
29+
detailedOwnerLogin (fromRightS userInfo) `shouldBe` "mike-burns"
30+
31+
it "returns information about the user" $ withAuth $ \auth -> do
32+
userInfo <- userInfoFor' (Just auth) "mike-burns"
1733
detailedOwnerLogin (fromRightS userInfo) `shouldBe` "mike-burns"

0 commit comments

Comments
 (0)