Skip to content

Commit

Permalink
Update tooling and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yurrriq committed Apr 22, 2016
1 parent f7dea65 commit 346f1a6
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: erlang
git:
submodules: false
install: true
before_script:
- wget https://s3.amazonaws.com/rebar3/rebar3
- chmod +x rebar3
env: PATH=$PATH:.
script: rebar3 eunit
notifications:
email: [email protected]
otp_release:
- 18.2
- 17.5
- R16B03-1
- R15B03
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# elli_xpblfe

[![Build Status](https://travis-ci.org/quasiquoting/elli_xpblfe.svg?branch=master)](https://travis-ci.org/quasiquoting/elli_xpblfe)
[![img](https://img.shields.io/hexpm/v/elli_xpblfe.svg)](https://hex.pm/packages/elli_xpblfe)
[![img](https://img.shields.io/badge/docs-100%25-green.svg)](http://quasiquoting.org/elli_xpblfe)

An [elli][] middleware to add the following header to all responses:

```http
Expand All @@ -8,7 +12,16 @@ X-Powered-By: LFE

[elli]: https://github.com/knutin/elli

## Usage:

## Config

rebar.config:
```erlang
{elli_xpblfe, "0.1.1"}
```


## Usage

Just add it to the `mods` in your `elli_middleware` callback args:

Expand Down
2 changes: 1 addition & 1 deletion doc
Submodule doc updated from a613c0 to 00ff1d
19 changes: 17 additions & 2 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
{plugins, [rebar3_lfe_compile]}.
{plugins, [
{'lfe-compile', {git, "git://github.com/lfe-rebar3/compile.git",
{tag, "0.4.0"}}}
]}.

{provider_hooks, [{post, [{compile, {lfe, compile}}]}]}.

{project_plugins, [lodox]}.
{project_plugins, [
{lodox, {git, "git://github.com/lfe-rebar3/lodox.git", {tag, "0.13.1"}}}
]}.

{profiles, [
{test, [
{eunit_compile_opts, [{src_dirs, ["src", "test"]}]},
{deps, [
{ltest, {git, "git://github.com/lfex/ltest.git", {tag, "0.8.2"}}},
elli
]}
]}
]}.

{lodox, [
{apps, [
Expand Down
2 changes: 1 addition & 1 deletion src/elli_xpblfe.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{application, elli_xpblfe, [
{description, "Elli middleware to add X-Powered-By: LFE header."},
{vsn, "0.1.0"},
{vsn, "0.1.1"},
{registered, []},
{applications, [kernel, stdlib]},
{env, []},
Expand Down
59 changes: 59 additions & 0 deletions test/elli_xpblfe_tests.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(defmodule elli_xpblfe_tests
(behaviour ltest-unit)
(export (elli_xpblfe_test_ 0)))

(include-lib "ltest/include/ltest-macros.lfe")

(deftestgen elli_xpblfe
"Tests based on [`elli_middleware_tests`][1].
[1]: https://github.com/knutin/elli/blob/master/test/elli_middleware_tests.erl"
`#(setup ,(defsetup setup) ,(defteardown teardown)
[,(_test (hello_world)) ,(_test (short_circuit))]))


;;;===================================================================
;;; Tests
;;;===================================================================

(defun short_circuit ()
(let* ((url "http://localhost:3002/middleware/short-circuit")
(`#(ok ,response) (httpc:request url)))
(is-equal 200 (status response))
(is-equal "LFE" (x_powered_by response))
(is-equal "short circuit!" (body response))))

(defun hello_world ()
(let* ((url "http://localhost:3002/hello/world")
(`#(ok ,response) (httpc:request url)))
(is-equal 200 (status response))
(is-equal "LFE" (x_powered_by response))
(is-equal "Hello World!" (body response))))


;;;===================================================================
;;; Helper functions
;;;===================================================================

(defun status ([`#(#(,_ ,status ,_) ,_ ,_)] status))

(defun headers ([`#(,_ ,headers ,_)] (lists:sort headers)))

(defun body ([`#(,_ ,_ ,body)] body))

(defun x_powered_by (response)
(proplists:get_value "x-powered-by" (headers response)))

(defun setup ()
(application:ensure_all_started 'inets)
(let* ((config `[#(mods [#(elli_example_middleware [])
#(elli_middlware_compress [])
#(elli_example_callback [])
#(elli_xpblfe [])])])
(`#(ok ,p) (elli:start_link `[#(callback elli_middleware)
#(callback_args ,config)
#(port 3002)])))
(unlink p)
`[,p]))

(defun teardown (pids) (lists:map #'elli:stop/1 pids))

0 comments on commit 346f1a6

Please sign in to comment.