You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.5 KiB
Clojure

; Copyright (c) meissa. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(ns cryogen-core.classpath-able-io-test
(:require [clojure.test :refer :all]
5 years ago
[clojure.java.io :as io]
[schema.core :as s]
5 years ago
[cryogen-core.classpath-able-io :as sut]))
(s/set-fn-validation! true)
5 years ago
(def theme "bootstrap4-test")
(def target "target/tmp")
5 years ago
(defn verify-file-exists [path]
(.exists (io/file path)))
(defn verify-dir-exists [path]
(and (verify-file-exists path)
(.isDirectory (io/file path))))
(deftest test-get-resource-paths-recursive
5 years ago
(is (=
[]
(sut/get-resource-paths-recursive "" "templates/themes/bootstrap4-test" ["not-existing"])))
5 years ago
(is (=
5 years ago
["js/dummy.js"]
(sut/get-resource-paths-recursive "" "templates/themes/bootstrap4-test" ["js/dummy.js"])))
5 years ago
(is (=
["js/subdir"
"js/subdir/test.js"
"js/subdir/subdummy.js"]
(sut/get-resource-paths-recursive "" "templates/themes/bootstrap4-test" ["js/subdir"])))
5 years ago
(is (=
["."
"./css"
"./css/dummy.css"
"./js"
"./js/subdir"
"./js/subdir/test.js"
"./js/subdir/subdummy.js"
"./js/dummy.js"
"./html"
"./html/403.html"
"./html/404.html"]
(sut/get-resource-paths-recursive "" "templates/themes/bootstrap4-test" ["."])))
5 years ago
)
5 years ago
(deftest test-delete-resource-recursive
(is
(do
(.mkdir (io/file (str "target/tmp" target)))
(sut/delete-resource-recursive! (str "target/tmp" target))
(not (verify-dir-exists (str "target/tmp" target))))))
5 years ago
(deftest test-file-from-cp-or-filesystem
(is
(.exists (sut/file-from-cp-or-filesystem
"./test-resources/" "templates/themes/bootstrap4-test/js")))
(is
(.exists (sut/file-from-cp-or-filesystem
"./" ".gitkeep"))))
(deftest test-filter-for-ignore-patterns
(is (=
["file.js"]
(sut/filter-for-ignore-patterns #".*\.ignore" ["file.js" "file.ignore"]))))
(deftest test-file-from-cp
(is
(sut/file-from-cp ".gitkeep")))
(deftest test-file-from-cp-or-filesystem
(is
(.exists (sut/file-from-cp-or-filesystem
"./test-resources/" "templates/themes/bootstrap4-test/js")))
(is
(.exists (sut/file-from-cp-or-filesystem
"./" ".gitkeep"))))
(deftest test-copy-resources-from-theme! (is (do
(sut/delete-resource-recursive! (str "target/tmp" target))
(sut/copy-resources-from-theme! "./" theme target "")
(and (verify-dir-exists
(str target "/templates/themes/bootstrap4-test/js"))
(verify-file-exists
(str target "/templates/themes/bootstrap4-test/js/dummy.js"))
(verify-dir-exists
(str target "/templates/themes/bootstrap4-test/js/subdir"))
(verify-file-exists
(str target "/templates/themes/bootstrap4-test/js/subdir/subdummy.js"))
(verify-file-exists
(str target "/templates/themes/bootstrap4-test/css/dummy.css"))
(verify-file-exists
(str target "/templates/themes/bootstrap4-test/html/404.html"))
))))