80 | 80 |
(to-bool "hi")
|
81 | 81 |
(is (not true) "Expected exception to be thrown by to-bool when an invalid string is passed")
|
82 | 82 |
(catch map? m
|
83 | |
(is (contains? m :type))
|
84 | |
(is (= :puppetlabs.kitchensink.core/parse-error (:type m)))
|
85 | |
(is (= :parse-error (without-ns (:type m))))
|
86 | |
(is (contains? m :message))
|
87 | |
(is (re-find #"Unable to parse 'hi' to a boolean" (:message m)))))))
|
|
83 |
(is (contains? m :kind))
|
|
84 |
(is (= :puppetlabs.kitchensink.core/parse-error (:kind m)))
|
|
85 |
(is (= :parse-error (without-ns (:kind m))))
|
|
86 |
(is (contains? m :msg))
|
|
87 |
(is (re-find #"Unable to parse 'hi' to a boolean" (:msg m)))))))
|
88 | 88 |
|
89 | 89 |
(deftest test-true-str?
|
90 | 90 |
(are [t-or-f? str-val] (t-or-f? (true-str? str-val))
|
|
124 | 124 |
(mkdirs! (fs/file tmpdir "foo" "bar" "baz"))
|
125 | 125 |
(is (not true) "Expected exception to be thrown by mkdirs! when one of the elements of the path already exists and is a file")
|
126 | 126 |
(catch map? m
|
127 | |
(is (contains? m :type))
|
128 | |
(is (= :puppetlabs.kitchensink.core/io-error (:type m)))
|
129 | |
(is (= :io-error (without-ns (:type m))))
|
130 | |
(is (contains? m :message))
|
131 | |
(is (re-find #"foo/bar' is a file" (:message m)))))))
|
|
127 |
(is (contains? m :kind))
|
|
128 |
(is (= :puppetlabs.kitchensink.core/io-error (:kind m)))
|
|
129 |
(is (= :io-error (without-ns (:kind m))))
|
|
130 |
(is (contains? m :msg))
|
|
131 |
(is (re-find #"foo/bar' is a file" (:msg m)))))))
|
132 | 132 |
(testing "throws exception if the path exists and is a file"
|
133 | 133 |
(let [tmpdir (temp-dir)]
|
134 | 134 |
(fs/mkdirs (fs/file tmpdir "foo"))
|
|
138 | 138 |
(is (not true) (str "Expected exception to be thrown by mkdirs! when "
|
139 | 139 |
"the path already exists and is a file"))
|
140 | 140 |
(catch map? m
|
141 | |
(is (contains? m :type))
|
142 | |
(is (= :puppetlabs.kitchensink.core/io-error (:type m)))
|
143 | |
(is (= :io-error (without-ns (:type m))))
|
144 | |
(is (contains? m :message))
|
145 | |
(is (re-find #"foo/bar' is a file" (:message m)))))))
|
|
141 |
(is (contains? m :kind))
|
|
142 |
(is (= :puppetlabs.kitchensink.core/io-error (:kind m)))
|
|
143 |
(is (= :io-error (without-ns (:kind m))))
|
|
144 |
(is (contains? m :msg))
|
|
145 |
(is (re-find #"foo/bar' is a file" (:msg m)))))))
|
146 | 146 |
(testing "Permission denied on some directory in the hierarchy"
|
147 | 147 |
(let [tmpdir (temp-dir)]
|
148 | 148 |
(fs/mkdirs (fs/file tmpdir "foo"))
|
|
151 | 151 |
(mkdirs! (fs/file tmpdir "foo" "bar" "baz"))
|
152 | 152 |
(is (not true) "Expected exception to be thrown by mkdirs! when a permissions error occurs")
|
153 | 153 |
(catch map? m
|
154 | |
(is (contains? m :type))
|
155 | |
(is (= :puppetlabs.kitchensink.core/io-error (:type m)))
|
156 | |
(is (= :io-error (without-ns (:type m))))
|
157 | |
(is (contains? m :message))
|
158 | |
(is (re-find #"foo' is not writable" (:message m))))))))
|
|
154 |
(is (contains? m :kind))
|
|
155 |
(is (= :puppetlabs.kitchensink.core/io-error (:kind m)))
|
|
156 |
(is (= :io-error (without-ns (:kind m))))
|
|
157 |
(is (contains? m :msg))
|
|
158 |
(is (re-find #"foo' is not writable" (:msg m))))))))
|
159 | 159 |
|
160 | 160 |
(deftest quotient-test
|
161 | 161 |
(testing "quotient"
|
|
466 | 466 |
(try+
|
467 | 467 |
(cli! [] [["-r" "--required" "A required field"]] [:required])
|
468 | 468 |
(catch map? m
|
469 | |
(is (contains? m :type))
|
470 | |
(is (= :puppetlabs.kitchensink.core/cli-error (:type m)))
|
471 | |
(is (= :cli-error (without-ns (:type m))))
|
472 | |
(is (contains? m :message))
|
|
469 |
(is (contains? m :kind))
|
|
470 |
(is (= :puppetlabs.kitchensink.core/cli-error (:kind m)))
|
|
471 |
(is (= :cli-error (without-ns (:kind m))))
|
|
472 |
(is (contains? m :msg))
|
473 | 473 |
(reset! got-expected-error true)))
|
474 | 474 |
(is (true? @got-expected-error))))
|
475 | 475 |
|
|
478 | 478 |
(try+
|
479 | 479 |
(cli! ["--help"] [] [])
|
480 | 480 |
(catch map? m
|
481 | |
(is (contains? m :type))
|
482 | |
(is (= :puppetlabs.kitchensink.core/cli-help (:type m)))
|
483 | |
(is (= :cli-help (without-ns (:type m))))
|
484 | |
(is (contains? m :message))
|
|
481 |
(is (contains? m :kind))
|
|
482 |
(is (= :puppetlabs.kitchensink.core/cli-help (:kind m)))
|
|
483 |
(is (= :cli-help (without-ns (:kind m))))
|
|
484 |
(is (contains? m :msg))
|
485 | 485 |
(reset! got-expected-help true)))
|
486 | 486 |
(is (true? @got-expected-help))))
|
487 | 487 |
|
|
509 | 509 |
args ["--bar"]]
|
510 | 510 |
(cli! args specs))
|
511 | 511 |
(catch map? m
|
512 | |
(is (= :puppetlabs.kitchensink.core/cli-error (:type m)))
|
513 | |
(is (contains? m :message))
|
|
512 |
(is (= :puppetlabs.kitchensink.core/cli-error (:kind m)))
|
|
513 |
(is (contains? m :msg))
|
514 | 514 |
(is (re-find
|
515 | 515 |
#"Unknown option.*--bar"
|
516 | |
(m :message)))
|
|
516 |
(m :msg)))
|
517 | 517 |
(reset! got-expected-exception true)))
|
518 | 518 |
(is (true? @got-expected-exception)))))
|
519 | 519 |
|