Skip to content

Commit 9e41637

Browse files
committed
Add tests
1 parent 3d08f7b commit 9e41637

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/eca/shared_test.clj

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,29 @@
101101
(is (= 1
102102
@(shared/future* {:env "prod"}
103103
1)))))
104+
105+
(deftest obfuscate-test
106+
(testing "nil and empty inputs"
107+
(is (nil? (shared/obfuscate nil)))
108+
(is (= "" (shared/obfuscate ""))))
109+
110+
(testing "length <= 4 is fully obfuscated"
111+
(is (= "*" (shared/obfuscate "a")))
112+
(is (= "**" (shared/obfuscate "ab")))
113+
(is (= "****" (shared/obfuscate "abcd"))))
114+
115+
(testing "default preserve-num=3 with various lengths"
116+
;; length 5: middle forced to at least 5 stars, preserve shrinks to floor(len/2)
117+
(is (= "ab*****de" (shared/obfuscate "abcde")))
118+
;; length 6: prefix 3, 5 stars, suffix 3 => 11 chars
119+
(is (= "abc*****def" (shared/obfuscate "abcdef")))
120+
;; length 7: prefix 3, 5 stars, suffix 3 => 11 chars
121+
(is (= "abc*****efg" (shared/obfuscate "abcdefg")))
122+
;; length 10: prefix 3, 5 stars, suffix 3 => 11 chars
123+
(is (= "abc*****hij" (shared/obfuscate "abcdefghij"))))
124+
125+
(testing "respect (bounded) preserve-num"
126+
;; preserve-num smaller than half the length
127+
(is (= "a*****f" (shared/obfuscate "abcdef" :preserve-num 1)))
128+
;; preserve-num larger than half the length is capped
129+
(is (= "abc*****def" (shared/obfuscate "abcdef" :preserve-num 10)))))

0 commit comments

Comments
 (0)