Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/brabster/docker-fixture
- Owner: brabster
- License: epl-1.0
- Created: 2016-12-03T20:29:22.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-11T11:13:42.000Z (over 7 years ago)
- Last Synced: 2024-08-10T03:17:14.363Z (3 months ago)
- Language: Clojure
- Size: 11.7 KB
- Stars: 21
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
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.