Skip to content

Commit

Permalink
adjust valid?
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtuannguyen committed Jul 9, 2016
1 parent 1c11ef6 commit 938fcad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
:unit :unit
:focused :focused
:all (constantly true)}
:aliases {"test" ["do" ["cljfmt" "fix"] "test"]
"test-refresh" ["do" ["cljfmt" "fix"] "test-refresh"]}
:profiles {:uberjar {:aot :all}
:test {:resource-paths ["test-resources"]}
:dev {:dependencies [[pjstadig/humane-test-output "0.8.0"]]
:plugins [[lein-cljfmt "0.5.3"]
[lein-cloverage "1.0.6"]
[jonase/eastwood "0.2.3"]
[lein-kibit "0.1.2"]]}})
[lein-kibit "0.1.2"]]}})
5 changes: 3 additions & 2 deletions src/cljocker/hh/dsl/docker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
m
(conj m result))))

(defn valid? [definition]
(defn valid? [[first & rest :as definition]]
(and (not (nil? definition))
(even? (count definition))
(= :from (first definition))
(= :from first)
(= 0 (count (filter empty? (take-nth 2 rest))))
(subset? (set (take-nth 2 definition))
DOCKER-INSTRUCTION)))

Expand Down
8 changes: 5 additions & 3 deletions test/cljocker/hh/dsl/docker_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

(deftest ^:unit valid?
(is (true? (d/valid? [:from "image"])))
(is (false? (d/valid? [:from ""])))
(is (false? (d/valid? [:from "image" :cmd])))
(is (false? (d/valid? [:from "image" :cmd ""])))
(is (false? (d/valid? [:from "image" :bla "blub"])))
(is (false? (d/valid? [:cmd "echo"]))))

(deftest ^:unit test-docker-dsl
(testing "edgecase"
(testing "edge case"
(is (= [] (d/docker [:from])))
(is (= [] (d/docker []))))

(testing "happy-case"
(testing "happy case"
(is (= ["FROM java:8"
"RUN mkdir -p /var/opt/folder"
"USER nobody"
Expand All @@ -30,7 +32,7 @@
:workdir "/var/opt/folder"
:cmd (java-cmd-with-heap-size 512)])))))

(deftest ^:unit write-file
(deftest ^:unit write-docker-file-to-disk
(let [definition [:from "java:8"
:cmd (java-cmd-with-heap-size 512)]
path "target"
Expand Down

0 comments on commit 938fcad

Please sign in to comment.