-
-
Save javahippie/c5e85360896eef1f53ee21a3f81418c7 to your computer and use it in GitHub Desktop.
An early, naive draft for a testcontainers kaocha plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns com.lambdaschmiede.kaocha-testcontainers | |
(:require [kaocha.plugin :as p] | |
[clj-test-containers.core :as tc])) | |
(def ^:dynamic for-all-scope {}) | |
(def ^:dynamic for-each-scope {}) | |
(defn get-container [id] | |
(get (merge for-each-scope for-all-scope) id)) | |
(defn- containers-for [type config] | |
(filter (fn [{:keys [for]}] (= type for)) config)) | |
(defn- start-containers [type kaocha-testcontainers] | |
(into {} | |
(for [{:keys [id config]} (containers-for type kaocha-testcontainers)] | |
[id (tc/start! (tc/create config))]))) | |
(p/defplugin com.lambdaschmiede.kaocha-testcontainers/plugin | |
;; Runs before each individual test | |
(pre-test [test {:keys [kaocha-testcontainers]}] | |
(def tst test) | |
(let [test-var (:kaocha.var/test test)] | |
(assoc test :kaocha.var/test (fn [] | |
(binding [for-each-scope (start-containers :each kaocha-testcontainers)] | |
(let [res (test-var)] | |
(for [[_ container] for-each-scope] | |
(tc/stop! container)) | |
res)))))) | |
;; Allows "wrapping" the run function | |
(wrap-run [run {:keys [kaocha-testcontainers]}] | |
(fn [test test-plan] | |
(binding [for-all-scope (start-containers :all kaocha-testcontainers)] | |
(let [result (run test test-plan)] | |
(tc/perform-cleanup!) | |
result))))) | |
(comment | |
(require '[kaocha.repl :as k]) | |
(k/run :unit)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment