Faultex

ci

Faultex is a simple Elixir fault injection library.

USAGE

Faultex can be use with the Plug and HTTPoison

Faultex.Plug

Add the :faultex to your project’s mix.exs:

defp deps do
  [
    {:plug, "~> 1.0"},
    {:faultex, "~> 0.1"}
  ]
end
  defmodule MyRouter do
    use Faultex.Plug, injectors: [
     %Faultex.Injector.SlowInjector{
      path: "/test/*/bar",
      headers: [{"X-Fault-Inject", "auth-failed"}],
      percentage: 100,
      resp_delay: 1000
     }
    ]
     
    get "test/:foo/bar" do
      ...
    end
  end

Faultex.HTTPoison

Add the :faultex to your project’s mix.exs:

defp deps do
  [
    {:httpoison, "~> 1.0"},
    {:faultex, "~> 0.1"}
  ]
end
defmodule MyApp.HTTPoison do
  use Faultex.HTTPoison, injectors: [
     %Faultex.Injector.FaultInjector{
      path: "/test/*/bar",
      method: "GET",
      headers: [{"X-Fault-Inject", "auth-failed"}],
      percentage: 100,
      resp_status: 401,
      resp_body: Jason.encode!(%{message: "Autharization failed"}),
      resp_headers: [],
      resp_delay: 1000
      }
    ]
end

alias MyApp.HTTPoison as HTTPoison

# receive 401
res = HTTPoison.request!(:get, "test/foo/bar", body, headers)

> res%{
}

Use config.exs

 config :faultex, 
   injectors: [{:register_fail, Faultex.Injector.FaultInjector}]
     
 config :faultex, :register_fail 
   # Request matcher parameters
   host: "example.com"
   path: "/auth/*/*/register",
   method: "POST",
   exact: true,
   header: {"X-Fault-Inject", "auth-failed"},
   percentage: 100,

   # Response parameters
   resp_status: 401,
   resp_handler: MyApp.FailureHandler,
   resp_body: Jason.encode!(%{message: "Autharization failed"}),
   resp_headers: [],
   resp_delay: 1000
use Faultex.HTTPoison, Application.compile_env!(faultex, :injectors)

Global Parameters

Fault Injector Configuration

In some request match parameters, you can set "*". which means matches all incoming parameters.

TODO