Applied autoformatter

This commit is contained in:
Tim Zöller 2022-03-18 14:05:20 +01:00
parent 71af11f503
commit 28b0183339
2 changed files with 46 additions and 45 deletions

View file

@ -1,25 +1,26 @@
(ns clj-test-containers.core (ns clj-test-containers.core
(:require (:require
[clj-test-containers.spec.core :as cs] [clj-test-containers.spec.core :as cs]
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.string]) [clojure.string])
(:import (:import
(java.nio.file (java.nio.file
Paths) Paths)
(org.testcontainers.containers (java.time
BindMode Duration)
GenericContainer (org.testcontainers.containers
Network) BindMode
(org.testcontainers.containers.output GenericContainer
ToStringConsumer) Network)
(org.testcontainers.containers.wait.strategy (org.testcontainers.containers.output
Wait) ToStringConsumer)
(org.testcontainers.images.builder (org.testcontainers.containers.wait.strategy
ImageFromDockerfile) Wait)
(org.testcontainers.utility (org.testcontainers.images.builder
MountableFile ImageFromDockerfile)
ResourceReaper) (org.testcontainers.utility
(java.time Duration))) MountableFile
ResourceReaper)))
(defn- resolve-bind-mode (defn- resolve-bind-mode
(^BindMode [bind-mode] (^BindMode [bind-mode]
@ -32,7 +33,7 @@
(ResourceReaper/instance)) (ResourceReaper/instance))
(defmulti wait (defmulti wait
"Sets a wait strategy to the container. Supports :http, :health and :log as "Sets a wait strategy to the container. Supports :http, :health and :log as
strategies. strategies.
## HTTP Strategy ## HTTP Strategy
@ -78,7 +79,7 @@
(wait {:wait-strategy :log (wait {:wait-strategy :log
:message \"accept connections\"} container) :message \"accept connections\"} container)
```" ```"
:wait-strategy) :wait-strategy)
(defmethod wait :http (defmethod wait :http
[{:keys [path [{:keys [path
@ -214,11 +215,11 @@
[{:keys [^GenericContainer container] :as container-config} [{:keys [^GenericContainer container] :as container-config}
{:keys [^String resource-path ^String container-path mode]}] {:keys [^String resource-path ^String container-path mode]}]
(assoc container-config (assoc container-config
:container :container
(.withClasspathResourceMapping container (.withClasspathResourceMapping container
resource-path resource-path
container-path container-path
(resolve-bind-mode mode)))) (resolve-bind-mode mode))))
(defn bind-filesystem! (defn bind-filesystem!
"Binds a source from the filesystem to the given container path. Should be "Binds a source from the filesystem to the given container path. Should be
@ -226,11 +227,11 @@
[{:keys [^GenericContainer container] :as container-config} [{:keys [^GenericContainer container] :as container-config}
{:keys [^String host-path ^String container-path mode]}] {:keys [^String host-path ^String container-path mode]}]
(assoc container-config (assoc container-config
:container :container
(.withFileSystemBind container (.withFileSystemBind container
host-path host-path
container-path container-path
(resolve-bind-mode mode)))) (resolve-bind-mode mode))))
(defn copy-file-to-container! (defn copy-file-to-container!
"If a container is not yet started, adds a mapping from mountable file to "If a container is not yet started, adds a mapping from mountable file to
@ -247,10 +248,10 @@
(.copyFileToContainer container mountable-file container-path) (.copyFileToContainer container mountable-file container-path)
container-config) container-config)
(assoc container-config (assoc container-config
:container :container
(.withCopyFileToContainer container (.withCopyFileToContainer container
mountable-file mountable-file
container-path))))) container-path)))))
(defn execute-command! (defn execute-command!
"Executes a command in the container, and returns the result" "Executes a command in the container, and returns the result"
@ -261,7 +262,7 @@
:stderr (.getStderr result)})) :stderr (.getStderr result)}))
(defmulti log (defmulti log
"Sets a log strategy on the container as a means of accessing the container "Sets a log strategy on the container as a means of accessing the container
logs. It currently only supports a :string as the strategy to use. logs. It currently only supports a :string as the strategy to use.
## String Strategy ## String Strategy
@ -282,7 +283,7 @@
(tc/dump-logs container-config) (tc/dump-logs container-config)
``` ```
" "
:log-strategy) :log-strategy)
(defmethod log :string (defmethod log :string
[_ ^GenericContainer container] [_ ^GenericContainer container]
@ -292,9 +293,9 @@
(-> (.toUtf8String to-string-consumer) (-> (.toUtf8String to-string-consumer)
(clojure.string/replace #"\n+" "\n")))})) (clojure.string/replace #"\n+" "\n")))}))
(defmethod log :slf4j [_ _] nil) ;; Not yet implemented (defmethod log :slf4j [_ _] nil) ; Not yet implemented
(defmethod log :default [_ _] nil) ;; Not yet implemented (defmethod log :default [_ _] nil) ; Not yet implemented
(defn dump-logs (defn dump-logs
"Dumps the logs found by invoking the function on the :string-log key" "Dumps the logs found by invoking the function on the :string-log key"
@ -365,7 +366,7 @@
(.performCleanup ^ResourceReaper (reaper-instance))) (.performCleanup ^ResourceReaper (reaper-instance)))
;;; REPL Helpers ;; REPL Helpers
(comment (comment
(start! (create {:image-name "postgres:12.1"})) (start! (create {:image-name "postgres:12.1"}))
(perform-cleanup!)) (perform-cleanup!))

View file

@ -1,11 +1,11 @@
(ns clj-test-containers.core-test (ns clj-test-containers.core-test
(:require (:require
[clj-test-containers.core :as sut] [clj-test-containers.core :as sut]
[clojure.string :refer [includes?]] [clojure.string :refer [includes?]]
[clojure.test :refer [deftest is testing]]) [clojure.test :refer [deftest is testing]])
(:import (:import
(org.testcontainers.containers (org.testcontainers.containers
PostgreSQLContainer))) PostgreSQLContainer)))
(deftest create-test (deftest create-test
(testing "Testing basic testcontainer generic image initialisation" (testing "Testing basic testcontainer generic image initialisation"