Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/brabster/docker-fixture

Docker containers as clojure.test fixtures
https://github.com/brabster/docker-fixture

Last synced: 1 day ago
JSON representation

Docker containers as clojure.test fixtures

Awesome Lists containing this project

README

        

* docker-fixture

Docker containers as clojure.test fixtures

[[https://travis-ci.org/brabster/docker-fixture][https://img.shields.io/travis/brabster/docker-fixture.svg]]
[[https://github.com/brabster/docker-fixture/releases/latest][https://img.shields.io/github/release/brabster/docker-fixture.svg]]

Get the latest version on [[https://clojars.org/docker-fixture][Clojars]]

* Usage

#+BEGIN_SRC clojure
(ns docker.fixture-test
(:require [docker.fixture :as docker]
[clj-http.lite.client :as http]
[clojure.test :refer :all]))

;; get a random port in the ephemeral range
(def port (docker/rand-port))

;; get the docker host we should connect to
(def host (docker/host))

;; prove interaction with fixture by init-fn
(def fixture-response (atom nil))

;; easy http GET
(defn component-http-get
([host port]
(http/get (str "http://" host ":" port "/knock-knock"))))

;; start and HTTP server that echos responses
;; request it in init-fn and put the response in the fixture-response atom...
(use-fixtures :once
(docker/new-fixture {:cmd ["docker" "run" "-d" "-p" (str port ":80") "keisato/http-echo"]
:sleep 500
:init-fn (fn [component]
(reset! fixture-response
(component-http-get (:host component) port)))}))

;; did the init-fn interact with the fixture?
(deftest test-fixture-init
(is (= 200 (:status @fixture-response))))

;; can we interact with the fixture now?
(deftest test-fixture-interact
(is (= 200 (:status (component-http-get host port)))))
#+END_SRC

* License

Copyright © 2016 Paul Brabban

Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.