Skip to content

Commit

Permalink
add maru_testing example
Browse files Browse the repository at this point in the history
  • Loading branch information
falood committed Nov 20, 2016
1 parent 4bb7958 commit 0dcc0b4
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 0 deletions.
17 changes: 17 additions & 0 deletions maru_testing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The directory Mix will write compiled artifacts to.
/_build

# If you run "mix test --cover", coverage assets end up here.
/cover

# The directory Mix downloads your dependencies sources to.
/deps

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez
24 changes: 24 additions & 0 deletions maru_testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# MaruTesting

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed as:

1. Add `maru_testing` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:maru_testing, "~> 0.1.0"}]
end
```

2. Ensure `maru_testing` is started before your application:

```elixir
def application do
[applications: [:maru_testing]]
end
```

30 changes: 30 additions & 0 deletions maru_testing/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.

# You can configure for your application as:
#
# config :maru_testing, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:maru_testing, :key)
#
# Or configure a 3rd-party app:
#
# config :logger, level: :info
#

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
74 changes: 74 additions & 0 deletions maru_testing/lib/maru_testing.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
defmodule MaruTesting do
end

defmodule NUL do
def init([]), do: []
def call(conn, []) do
conn
end
end

defmodule TA do
def init([]), do: []
def call(conn, []) do
conn |> Plug.Conn.put_private(:maru_plug_ta, 0)
end
end

defmodule TB1 do
def init([]), do: []
def call(conn, []) do
conn |> Plug.Conn.put_private(:maru_plug_tb, 1)
end
end

defmodule TB2 do
def init([]), do: []
def call(conn, []) do
conn |> Plug.Conn.put_private(:maru_plug_tb, 2)
end
end

defmodule A1 do
use Maru.Router

pipeline do
plug_overridable :test_a, NUL
end
get do
text(conn, "A1")
end
end

defmodule A2 do
use Maru.Router

get do
text(conn, "A2")
end
end


defmodule B1 do
use Maru.Router
plug_overridable :test_b, TB1

mount A1
mount A2
end

defmodule B2 do
use Maru.Router
plug_overridable :test_b, TB2

mount A1
mount A2
end

defmodule API do
use Maru.Router
plug_overridable :test_a, TA

mount B1
mount B2
end
21 changes: 21 additions & 0 deletions maru_testing/mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule MaruTesting.Mixfile do
use Mix.Project

def project do
[ app: :maru_testing,
version: "0.1.0",
elixir: "~> 1.3",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps(),
]
end

def application do
[applications: [:logger, :maru]]
end

defp deps do
[{:maru, github: "falood/maru"}]
end
end
7 changes: 7 additions & 0 deletions maru_testing/mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%{"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:make, :rebar], [{:cowlib, "~> 1.0.0", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, optional: false]}]},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []},
"maru": {:git, "https://github.com/falood/maru.git", "f1304c2a354bafe1fc1e3fabd8d6fcf6108e2a7f", []},
"mime": {:hex, :mime, "1.0.1", "05c393850524767d13a53627df71beeebb016205eb43bfbd92d14d24ec7a1b51", [:mix], []},
"plug": {:hex, :plug, "1.2.2", "cfbda521b54c92ab8ddffb173fbaabed8d8fc94bec07cd9bb58a84c1c501b0bd", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}, {:mime, "~> 1.0", [hex: :mime, optional: false]}]},
"poison": {:hex, :poison, "3.0.0", "625ebd64d33ae2e65201c2c14d6c85c27cc8b68f2d0dd37828fde9c6920dd131", [:mix], []},
"ranch": {:hex, :ranch, "1.2.1", "a6fb992c10f2187b46ffd17ce398ddf8a54f691b81768f9ef5f461ea7e28c762", [:make], []}}
48 changes: 48 additions & 0 deletions maru_testing/test/maru_testing_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
defmodule MaruTestingTest do
use ExUnit.Case
doctest MaruTesting
end

defmodule B1A1Test do
use ExUnit.Case
use Maru.Test, for: B1 |> A1

test "/" do
private = get("/").private
assert 1 == private.maru_plug_tb
assert false == Map.has_key?(private, :maru_plug_ta)
end
end

defmodule B1A2Test do
use ExUnit.Case
use Maru.Test, for: B1 |> A2

test "/" do
private = get("/").private
assert 1 == private.maru_plug_tb
assert 0 == private.maru_plug_ta
end
end

defmodule B2A1Test do
use ExUnit.Case
use Maru.Test, for: B2 |> A1

test "/" do
private = get("/").private
assert 2 == private.maru_plug_tb
assert false == Map.has_key?(private, :maru_plug_ta)
end
end

defmodule B2A2Test do
use ExUnit.Case
use Maru.Test, for: B2 |> A2

test "/" do
private = get("/").private
assert 2 == private.maru_plug_tb
assert 0 == private.maru_plug_ta
end
end
2 changes: 2 additions & 0 deletions maru_testing/test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ExUnit.start()
Maru.Test.start()

0 comments on commit 0dcc0b4

Please sign in to comment.