Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ before_cache:
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log
- rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.tar

env:
global:
secure: "J522iO9HE8yIMwcbBBCXYiAJ0bZSzMjq9nue6oockCIZc3kSoF/IGhfBMns3KRrzMR7nD0IirpHB0jjSXIQLA+51SaWS8HG2+pI+U3qvCoeDIaB85Iyhk932GIymdySCH7ypw71AeuJTErvZ67TR3m+o98BBk8WgMCcLkGykWKA="

matrix:
include:
- env: CABALVER=1.18 GHCVER=7.8.4
Expand Down Expand Up @@ -73,7 +77,7 @@ script:
- if [ -f configure.ac ]; then autoreconf -i; fi
- cabal configure --enable-tests --enable-benchmarks -v2 # -v2 provides useful information for debugging
- cabal build # this builds all libraries and executables (including tests/benchmarks)
- cabal test
- cabal test --show-details=always

- if [ "$CABALVER" = "1.22" ]; then cabal check; fi
- if [ "$CABALVER" = "1.22" ]; then cabal haddock; fi
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ No support? Not sure.

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

Test setup
==========

To run integration part of tests, you'll need [github access token](https://github.com/settings/tokens/new)
Token is needed, because unauthorised access is highly limited.
It's enough to add only basic read access for public information.

With `travis encrypt --org --repo yournick/github "GITHUB_TOKEN=yourtoken"` command you get a secret,
you can use in your travis setup to run the test-suite there.

Contributions
=============
Expand Down
32 changes: 32 additions & 0 deletions fixtures/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"login": "mike-burns",
"id": 4550,
"avatar_url": "https://avatars.githubusercontent.com/u/4550?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/mike-burns",
"html_url": "https://github.com/mike-burns",
"followers_url": "https://api.github.com/users/mike-burns/followers",
"following_url": "https://api.github.com/users/mike-burns/following{/other_user}",
"gists_url": "https://api.github.com/users/mike-burns/gists{/gist_id}",
"starred_url": "https://api.github.com/users/mike-burns/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mike-burns/subscriptions",
"organizations_url": "https://api.github.com/users/mike-burns/orgs",
"repos_url": "https://api.github.com/users/mike-burns/repos",
"events_url": "https://api.github.com/users/mike-burns/events{/privacy}",
"received_events_url": "https://api.github.com/users/mike-burns/received_events",
"type": "User",
"site_admin": false,
"name": "Mike Burns",
"company": "thoughtbot",
"blog": "http://mike-burns.com/",
"location": "Stockholm, Sweden",
"email": "mburns@thoughtbot.com",
"hireable": true,
"bio": null,
"public_repos": 35,
"public_gists": 32,
"followers": 171,
"following": 0,
"created_at": "2008-04-03T17:54:24Z",
"updated_at": "2015-10-02T16:53:25Z"
}
6 changes: 5 additions & 1 deletion github.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Library
Build-depends: base >= 4.0 && < 5.0,
time >=1.4 && <1.6,
aeson >= 0.6.1.0,
aeson-extra >= 0.2.0.0,
aeson-extra >= 0.2.0.0 && <0.3,
attoparsec >= 0.10.3.0,
bytestring,
case-insensitive >= 0.4.0.4,
Expand Down Expand Up @@ -210,9 +210,13 @@ test-suite github-test
default-language: Haskell2010
type: exitcode-stdio-1.0
hs-source-dirs: spec
other-modules:
Github.UsersSpec
main-is: Spec.hs
build-depends: base >= 4.0 && < 5.0,
aeson-extra >= 0.2.0.0 && <0.3,
github,
file-embed,
hspec

ghc-options: -Wall -fno-warn-orphans
24 changes: 20 additions & 4 deletions spec/Github/UsersSpec.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
{-# LANGUAGE TemplateHaskell #-}
module Github.UsersSpec where

import Github.Users (userInfoFor)
import Github.Auth (GithubAuth(..))
import Github.Users (userInfoFor')
import Github.Data.Definitions (DetailedOwner(..))

import Test.Hspec (it, describe, shouldBe, Spec)
import Data.Aeson.Compat (eitherDecodeStrict)
import Test.Hspec (it, describe, shouldBe, pendingWith, Spec)
import System.Environment (lookupEnv)
import Data.FileEmbed (embedFile)

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 :: (GithubAuth -> IO ()) -> IO ()
withAuth action = do
mtoken <- lookupEnv "GITHUB_TOKEN"
case mtoken of
Nothing -> pendingWith "no GITHUB_TOKEN"
Just token -> action (GithubOAuth token)

spec :: Spec
spec =
describe "userInfoFor" $ do
it "returns information about the user" $ do
userInfo <- userInfoFor "mike-burns"
it "decodes user json" $ do
let userInfo = eitherDecodeStrict $(embedFile "fixtures/user.json") :: Either String DetailedOwner
detailedOwnerLogin (fromRightS userInfo) `shouldBe` "mike-burns"

it "returns information about the user" $ withAuth $ \auth -> do
userInfo <- userInfoFor' (Just auth) "mike-burns"
detailedOwnerLogin (fromRightS userInfo) `shouldBe` "mike-burns"