This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set +e | |
| echo "Preparing to run migrations" | |
| while true; do | |
| nodetool ping | |
| EXIT_CODE=$? | |
| if [ $EXIT_CODE -eq 0 ]; then | |
| echo "Application is up!" | |
| break |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # rel/config.exs | |
| use Mix.Releases.Config, | |
| default_release: :default, | |
| default_environment: Mix.env() | |
| … | |
| environment :prod do | |
| set include_erts: true | |
| set include_src: false | |
| set post_start_hooks: "rel/hooks/post_start" | |
| set cookie: :"~AP{<;FKd_!~gObmS]h.HBYU4z&[1p(>tvCXo`I1qo*ZDVM)f0c>Slw~`R.47O]C" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule GithubClient do | |
| @base_url "https://api.github.com/v3" | |
| def create_repo(params) do | |
| HTTPoison.post(@base_url <> "/repos", params, headers) | |
| |> handle_response | |
| end | |
| defp handle_response(resp) do | |
| case resp do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule GithubClient.Test do | |
| use ExUnit.Case, async: false | |
| import GithubRepo | |
| import Mock | |
| @create_repo_params %{name: "my-new-repo"} | |
| test_with_mock "create_repo when success", HTTPoison, | |
| [post: fn("repos", @create_repo_params, _headers) -> | |
| %HTTPoison.Response{body: %{name: "my-new-repo", id: 1}, headers: _list, request_url: _url, status_code: 200} end] do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defp deps do | |
| [ | |
| {:dialyxir, "~> 0.5", only: [:dev], runtime: false}, | |
| {:httpoison, "~> 1.0"}, | |
| {:plug_cowboy, "~> 2.0"} | |
| ] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # mix.exs | |
| def application do | |
| [ | |
| extra_applications: [:logger], | |
| mod: {GithubClient.Application, [env: Mix.env]}, | |
| applications: applications(Mix.env) | |
| ] | |
| end | |
| defp applications(:test), do: applications(:default) ++ [:cowboy, :plug] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lib/github_client/mock_server.ex | |
| defmodule GithubClient.MockServer do | |
| use GenServer | |
| alias GithubClient.MockServer.GithubApiMockController | |
| def init(args) do | |
| {:ok, args} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lib/github_client/mock_server.ex | |
| defmodule GithubClient.MockServer do | |
| use Plug.Router | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lib/github_client/application.ex | |
| ... | |
| def start(_type, args) do | |
| children = case args do | |
| [env: :prod] -> [] | |
| [env: :test] -> [{Plug.Cowboy, scheme: :http, plug: GithubClient.MockServer, options: [port: 8081]}] | |
| [env: :dev] -> [] | |
| [_] -> [] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule GithubClient.MockServer do | |
| use Plug.Router | |
| plug Plug.Parsers, parsers: [:json], | |
| pass: ["text/*"], | |
| json_decoder: Poison | |
| plug :match | |
| plug :dispatch | |
| end |