cljstyle redux, with pre-commit hook (#24)

* cljstyle redux, with pre-commit

* Use fork of lein-githooks with fixes for shell characters

* Remove stale doc
This commit is contained in:
Rob Hanlon 2020-08-09 12:38:20 -07:00 committed by GitHub
parent a327fc3f75
commit 36f3820f4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 72 additions and 32 deletions

View file

@ -17,10 +17,6 @@ jobs:
steps:
- checkout
- run:
name: Install Leiningen
command: wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein && chmod a+x lein && ./lein
# Download and cache dependencies
- restore_cache:
keys:
@ -28,15 +24,23 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Install Leiningen
command: wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein && chmod a+x lein && lein --version
- run: lein deps
- save_cache:
paths:
- ~/.lein
- ~/.m2
key: v1-dependencies-{{ checksum "project.clj" }}
# run tests!
- run: lein test
# check style
- run: lein cljstyle check --report
- store_test_results:
path: target

3
.cljstyle Normal file
View file

@ -0,0 +1,3 @@
{:file-pattern #"\.(clj[sc]?|edn|cljstyle)$"
:list-indent-size 1
:padding-lines 1}

View file

@ -372,9 +372,6 @@ Creates a network. The optional map accepts config values for enabling ipv6 and
(init-network)
```
## License
Copyright © 2020 Tim Zöller

View file

@ -9,12 +9,19 @@
:dependencies [[org.clojure/clojure "1.10.1"]
[org.testcontainers/testcontainers "1.14.3"]]
:aliases {"test" ["run" "-m" "kaocha.runner"]}
:aliases {"test" ["run" "-m" "kaocha.runner"]
"cljstyle" ["run" "-m" "cljstyle.main"]}
:plugins [[jainsahab/lein-githooks "1.0.0"]]
:profiles {:dev {:dependencies [[org.testcontainers/postgresql "1.14.3"]
[lambdaisland/kaocha-cloverage "1.0-45"]
[lambdaisland/kaocha "1.0.641"]
[lambdaisland/kaocha-junit-xml "0.0.76"]]}}
[lambdaisland/kaocha-junit-xml "0.0.76"]
[mvxcvi/cljstyle "0.13.0" :exclusions [org.clojure/clojure]]]
:githooks {:auto-install true
:ci-env-variable "CI"
:pre-commit ["script/pre-commit"]}}}
:target-path "target/%s")

21
script/pre-commit Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
if [[ -z "$FILES" ]]; then
exit 0
fi
echo "Fixing Clojure style..."
# Format all selected files
echo "$FILES" | xargs lein cljstyle fix --report
# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add
echo "Done!"

View file

@ -1,10 +1,17 @@
(ns clj-test-containers.core
(:require [clojure.spec.alpha :as s])
(:import [org.testcontainers.containers GenericContainer]
[org.testcontainers.utility MountableFile]
[org.testcontainers.containers BindMode Network]
[org.testcontainers.images.builder ImageFromDockerfile]
[java.nio.file Paths]))
(:require
[clojure.spec.alpha :as s])
(:import
(java.nio.file
Paths)
(org.testcontainers.containers
BindMode
GenericContainer
Network)
(org.testcontainers.images.builder
ImageFromDockerfile)
(org.testcontainers.utility
MountableFile)))
(defn- resolve-bind-mode
[bind-mode]
@ -115,7 +122,6 @@
(dissoc :id)
(dissoc :mapped-ports)))
(defn- build-network
[{:keys [ipv6 driver]}]
(let [builder (Network/builder)]

View file

@ -1,7 +1,10 @@
(ns clj-test-containers.core-test
(:require [clojure.test :refer :all]
[clj-test-containers.core :refer :all])
(:import [org.testcontainers.containers PostgreSQLContainer]))
(:require
[clj-test-containers.core :refer :all]
[clojure.test :refer :all])
(:import
(org.testcontainers.containers
PostgreSQLContainer)))
(deftest create-test
(testing "Testing basic testcontainer generic image initialisation"
@ -119,7 +122,6 @@
(is (nil? (:id stopped-container)))
(is (nil? (:mapped-ports stopped-container))))))
(deftest networking-test
(testing "Putting two containers into the same network and check their communication"
@ -128,8 +130,8 @@
:network network
:network-aliases ["foo"]
:command ["/bin/sh"
"-c"
"while true ; do printf 'HTTP/1.1 200 OK\\n\\nyay' | nc -l -p 8080; done"]})
"-c"
"while true ; do printf 'HTTP/1.1 200 OK\\n\\nyay' | nc -l -p 8080; done"]})
client-container (create {:image-name "alpine:3.5"
:network network
:command ["top"]})