Code Monkey home page Code Monkey logo

docker-fixture's Introduction

docker-fixture

Docker containers as clojure.test fixtures

https://img.shields.io/travis/brabster/docker-fixture.svg https://img.shields.io/github/release/brabster/docker-fixture.svg

Get the latest version on Clojars

Usage

(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)))))

License

Copyright © 2016 Paul Brabban

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

docker-fixture's People

Contributors

brabster avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.