|
2 | 2 | (:require |
3 | 3 | [babashka.fs :as fs] |
4 | 4 | [clojure.test :refer [deftest is testing]] |
| 5 | + [eca.config :as config] |
5 | 6 | [eca.features.rules :as f.rules] |
6 | 7 | [eca.test-helper :as h] |
7 | 8 | [matcher-combinators.matchers :as m] |
|
20 | 21 | (testing "absolute config rule" |
21 | 22 | (with-redefs [clojure.core/slurp (constantly "MY_RULE_CONTENT") |
22 | 23 | fs/absolute? (constantly true) |
23 | | - fs/exists? (constantly true) |
| 24 | + fs/exists? #(= (h/file-path "/path/to/my-rule.md") %) |
24 | 25 | fs/canonicalize identity |
25 | 26 | fs/file-name (constantly "cool-name")] |
26 | 27 | (let [config {:rules [{:path (h/file-path "/path/to/my-rule.md")}]}] |
|
33 | 34 |
|
34 | 35 | (testing "relative config rule" |
35 | 36 | (with-redefs [fs/absolute? (constantly false) |
36 | | - fs/exists? (constantly true) |
| 37 | + fs/exists? #(contains? #{(h/file-path "/my/project/.eca/rules") |
| 38 | + (h/file-path "/my/project/.foo/cool-rule.md")} (str %)) |
37 | 39 | fs/list-dir (constantly []) |
38 | 40 | fs/canonicalize identity |
39 | 41 | fs/file-name (constantly "cool-name") |
40 | 42 | clojure.core/slurp (constantly "MY_RULE_CONTENT")] |
41 | 43 | (let [config {:rules [{:path ".foo/cool-rule.md"}]} |
42 | 44 | roots [{:uri (h/file-uri "file:///my/project")}]] |
43 | 45 | (is (match? |
44 | | - (m/embeds [{:type :user-config |
45 | | - :path (h/file-path "/my/project/.foo/cool-rule.md") |
46 | | - :name "cool-name" |
47 | | - :content "MY_RULE_CONTENT"}]) |
48 | | - (f.rules/all config roots vars)))))) |
| 46 | + (m/embeds [{:type :user-config |
| 47 | + :path (h/file-path "/my/project/.foo/cool-rule.md") |
| 48 | + :name "cool-name" |
| 49 | + :content "MY_RULE_CONTENT"}]) |
| 50 | + (f.rules/all config roots vars)))))) |
49 | 51 |
|
50 | | - (testing "file rules" |
51 | | - (with-redefs [fs/exists? (constantly true) |
| 52 | + (testing "local file rules" |
| 53 | + (with-redefs [fs/exists? #(= (h/file-path "/my/project/.eca/rules") (str %)) |
| 54 | + fs/list-dir (constantly [(fs/path "cool.md")]) |
| 55 | + fs/canonicalize identity |
| 56 | + fs/file-name (constantly "cool-name") |
| 57 | + clojure.core/slurp (constantly "MY_RULE_CONTENT")] |
| 58 | + (let [roots [{:uri (h/file-uri "file:///my/project")}]] |
| 59 | + (is (match? |
| 60 | + (m/embeds [{:type :user-local-file |
| 61 | + :path "cool.md" |
| 62 | + :name "cool-name" |
| 63 | + :content "MY_RULE_CONTENT"}]) |
| 64 | + (f.rules/all {} roots vars)))))) |
| 65 | + (testing "global file rules" |
| 66 | + (with-redefs [config/get-env (constantly (h/file-path "/home/someuser/.config")) |
| 67 | + fs/exists? #(= (h/file-path "/home/someuser/.config/eca/rules") (str %)) |
52 | 68 | fs/list-dir (constantly [(fs/path "cool.md")]) |
53 | 69 | fs/canonicalize identity |
54 | 70 | fs/file-name (constantly "cool-name") |
55 | 71 | clojure.core/slurp (constantly "MY_RULE_CONTENT")] |
56 | 72 | (let [roots [{:uri (h/file-uri "file:///my/project")}]] |
57 | 73 | (is (match? |
58 | | - (m/embeds [{:type :user-file |
| 74 | + (m/embeds [{:type :user-global-file |
59 | 75 | :path "cool.md" |
60 | 76 | :name "cool-name" |
61 | 77 | :content "MY_RULE_CONTENT"}]) |
|
0 commit comments