Skip to content

Commit 50d2d29

Browse files
authored
Merge pull request #58 from dwyl/avoid-mix-env-issue-#51
Avoid `Mix.env()` issue #51
2 parents 8d20090 + 2e6a49c commit 50d2d29

File tree

9 files changed

+95
-42
lines changed

9 files changed

+95
-42
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Elixir CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
name: Build and test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Elixir
16+
uses: erlef/setup-elixir@885971a72ed1f9240973bd92ab57af8c1aa68f24
17+
with:
18+
elixir-version: '1.12.3' # Define the elixir version [required]
19+
otp-version: '24.0.2' # Define the OTP version [required]
20+
- name: Restore dependencies cache
21+
uses: actions/cache@v2
22+
with:
23+
path: deps
24+
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
25+
restore-keys: ${{ runner.os }}-mix-
26+
- name: Install dependencies
27+
run: mix deps.get
28+
- name: Run Tests
29+
run: mix coveralls.json
30+
env:
31+
MIX_ENV: test
32+
- name: Upload coverage to Codecov
33+
uses: codecov/codecov-action@v1

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Add a line for **`:elixir_auth_github`** in the **`deps`** list:
7373
```elixir
7474
def deps do
7575
[
76-
{:elixir_auth_github, "~> 1.6.0"}
76+
{:elixir_auth_github, "~> 1.6.1"}
7777
]
7878
end
7979
```
@@ -382,6 +382,15 @@ see:
382382
[`test/elixir_auth_github_test.exs`](https://github.com/dwyl/elixir-auth-github/blob/master/test/elixir_auth_github_test.exs)
383383

384384

385+
To use the tests add the following config to your `test.exs` file:
386+
387+
```
388+
config :elixir_auth_github,
389+
client_id: "d6fca75c63daa014c187",
390+
client_secret: "8eeb143935d1a505692aaef856db9b4da8245f3c",
391+
httpoison_mock: true
392+
```
393+
385394
<br /> <br />
386395

387396

config/config.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Config
2+
3+
if Mix.env() == :test do
4+
import_config "test.exs"
5+
end

config/test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Config
2+
3+
config :elixir_auth_github,
4+
client_id: "d6fca75c63daa014c187",
5+
client_secret: "8eeb143935d1a505692aaef856db9b4da8245f3c",
6+
httpoison_mock: true

lib/elixir_auth_github.ex

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,28 @@ defmodule ElixirAuthGithub do
99
@github_url "https://github.com/login/oauth/"
1010
@github_auth_url @github_url <> "access_token?"
1111

12+
@httpoison (Application.compile_env(:elixir_auth_github, :httpoison_mock) &&
13+
ElixirAuthGithub.HTTPoisonMock) || HTTPoison
14+
1215
@doc """
1316
`inject_poison/0` injects a TestDouble of HTTPoison in Test
1417
so that we don't have duplicate mock in consuming apps.
1518
see: https://github.com/dwyl/elixir-auth-google/issues/35
1619
"""
17-
def inject_poison() do
18-
(Mix.env() == :test && ElixirAuthGithub.HTTPoisonMock) || HTTPoison
20+
def inject_poison, do: @httpoison
21+
22+
@doc """
23+
`client_id/0` returns a `String` of the `GITHUB_CLIENT_ID`
24+
"""
25+
def client_id do
26+
System.get_env("GITHUB_CLIENT_ID") || Application.get_env(:elixir_auth_github, :client_id)
27+
end
28+
29+
@doc """
30+
`client_secret/0` returns a `String` of the `GITHUB_CLIENT_SECRET`
31+
"""
32+
def client_secret do
33+
System.get_env("GITHUB_CLIENT_SECRET") || Application.get_env(:elixir_auth_github, :client_secret)
1934
end
2035

2136
@doc """
@@ -25,8 +40,7 @@ defmodule ElixirAuthGithub do
2540
See step 2 of setup instructions.
2641
"""
2742
def login_url do
28-
client_id = System.get_env("GITHUB_CLIENT_ID")
29-
@github_url <> "authorize?client_id=#{client_id}"
43+
@github_url <> "authorize?client_id=#{client_id()}"
3044
end
3145

3246
@doc """
@@ -57,8 +71,8 @@ defmodule ElixirAuthGithub do
5771
def github_auth(code) do
5872
query =
5973
URI.encode_query(%{
60-
"client_id" => System.get_env("GITHUB_CLIENT_ID"),
61-
"client_secret" => System.get_env("GITHUB_CLIENT_SECRET"),
74+
"client_id" => client_id(),
75+
"client_secret" => client_secret(),
6276
"code" => code
6377
})
6478

mix.exs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ defmodule ElixirAuthGithub.Mixfile do
44
def project do
55
[
66
app: :elixir_auth_github,
7-
version: "1.6.0",
7+
version: "1.6.1",
88
elixir: "~> 1.12",
99
test_coverage: [tool: ExCoveralls],
1010
preferred_cli_env: [
11+
c: :test,
1112
coveralls: :test,
1213
"coveralls.detail": :test,
1314
"coveralls.post": :test,
@@ -18,7 +19,14 @@ defmodule ElixirAuthGithub.Mixfile do
1819
name: "ElixirAuthGithub",
1920
source_url: "https://www.github.com/dwyl/elixir-auth-github",
2021
description: description(),
21-
package: package()
22+
package: package(),
23+
aliases: aliases()
24+
]
25+
end
26+
27+
defp aliases do
28+
[
29+
c: ["coveralls.html"]
2230
]
2331
end
2432

@@ -36,10 +44,10 @@ defmodule ElixirAuthGithub.Mixfile do
3644
{:jason, "~> 1.2"},
3745

3846
# tracking test coverage
39-
{:excoveralls, "~> 0.14.2", only: [:test, :dev]},
47+
{:excoveralls, "~> 0.14.4", only: [:test, :dev]},
4048

4149
# documentation
42-
{:ex_doc, "~> 0.25.2", only: :dev}
50+
{:ex_doc, "~> 0.28.0", only: :dev}
4351
]
4452
end
4553

mix.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
%{
2-
"certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"},
2+
"certifi": {:hex, :certifi, "2.8.0", "d4fb0a6bb20b7c9c3643e22507e42f356ac090a1dcea9ab99e27e0376d695eba", [:rebar3], [], "hexpm", "6ac7efc1c6f8600b08d625292d4bbf584e14847ce1b6b5c44d983d273e1097ea"},
33
"earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"},
4-
"earmark_parser": {:hex, :earmark_parser, "1.4.15", "b29e8e729f4aa4a00436580dcc2c9c5c51890613457c193cc8525c388ccb2f06", [:mix], [], "hexpm", "044523d6438ea19c1b8ec877ec221b008661d3c27e3b848f4c879f500421ca5c"},
5-
"ex_doc": {:hex, :ex_doc, "0.25.3", "3edf6a0d70a39d2eafde030b8895501b1c93692effcbd21347296c18e47618ce", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "9ebebc2169ec732a38e9e779fd0418c9189b3ca93f4a676c961be6c1527913f5"},
6-
"excoveralls": {:hex, :excoveralls, "0.14.2", "f9f5fd0004d7bbeaa28ea9606251bb643c313c3d60710bad1f5809c845b748f0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ca6fd358621cb4d29311b29d4732c4d47dac70e622850979bc54ed9a3e50f3e1"},
4+
"earmark_parser": {:hex, :earmark_parser, "1.4.19", "de0d033d5ff9fc396a24eadc2fcf2afa3d120841eb3f1004d138cbf9273210e8", [:mix], [], "hexpm", "527ab6630b5c75c3a3960b75844c314ec305c76d9899bb30f71cb85952a9dc45"},
5+
"ex_doc": {:hex, :ex_doc, "0.28.0", "7eaf526dd8c80ae8c04d52ac8801594426ae322b52a6156cd038f30bafa8226f", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e55cdadf69a5d1f4cfd8477122ebac5e1fadd433a8c1022dafc5025e48db0131"},
6+
"excoveralls": {:hex, :excoveralls, "0.14.4", "295498f1ae47bdc6dce59af9a585c381e1aefc63298d48172efaaa90c3d251db", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e3ab02f2df4c1c7a519728a6f0a747e71d7d6e846020aae338173619217931c1"},
77
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
8-
"hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"},
8+
"hackney": {:hex, :hackney, "1.18.0", "c4443d960bb9fba6d01161d01cd81173089686717d9490e5d3606644c48d121f", [:rebar3], [{:certifi, "~>2.8.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "9afcda620704d720db8c6a3123e9848d09c87586dc1c10479c42627b905b5c5e"},
99
"httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"},
1010
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
11-
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
11+
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
1212
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], [], "hexpm"},
1313
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
14-
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
14+
"makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"},
1515
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
1616
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
1717
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
18-
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
18+
"nimble_parsec": {:hex, :nimble_parsec, "1.2.1", "264fc6864936b59fedb3ceb89998c64e9bb91945faf1eb115d349b96913cc2ef", [:mix], [], "hexpm", "23c31d0ec38c97bf9adde35bc91bc8e1181ea5202881f48a192f4aa2d2cf4d59"},
1919
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
2020
"poison": {:hex, :poison, "5.0.0", "d2b54589ab4157bbb82ec2050757779bfed724463a544b6e20d79855a9e43b24", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "11dc6117c501b80c62a7594f941d043982a1bd05a1184280c0d9166eb4d8d3fc"},
2121
"pre_commit": {:hex, :pre_commit, "0.1.3", "c623c822b5848bf273db5f16550f0c0277c5ded1c08c0ce92fc5a76cd9dd6f91", [:mix], [], "hexpm"},

test/elixir_auth_github_test.exs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
defmodule ElixirAuthGithubTest do
22
use ExUnit.Case
33
doctest ElixirAuthGithub
4-
5-
defp client_id do
6-
System.get_env("GITHUB_CLIENT_ID")
7-
end
4+
import ElixirAuthGithub
85

96
defp setup_test_environment_variables do
107
System.put_env([{"GITHUB_CLIENT_ID", "TEST_ID"}, {"GITHUB_CLIENT_SECRET", "TEST_SECRET"}])
@@ -58,7 +55,6 @@ defmodule ElixirAuthGithubTest do
5855

5956
test "github_auth returns an error with a bad code" do
6057
setup_test_environment_variables()
61-
6258
assert ElixirAuthGithub.github_auth("1234") ==
6359
{:error, %{"error" => "error"}}
6460
end

0 commit comments

Comments
 (0)