diff --git a/common/src/app/common/uuid.cljc b/common/src/app/common/uuid.cljc index 9b21f8f796..373382a6db 100644 --- a/common/src/app/common/uuid.cljc +++ b/common/src/app/common/uuid.cljc @@ -60,8 +60,9 @@ :cljs (uuid (impl/v4)))) (defn custom - ([a] #?(:clj (UUID. 0 a) :cljs (uuid (impl/custom 0 a)))) - ([b a] #?(:clj (UUID. b a) :cljs (uuid (impl/custom b a))))) + "Generate a uuid using directly the given number (specified as two long integers)" + ([low] #?(:clj (UUID. 0 low) :cljs (uuid (impl/custom 0 low)))) + ([high low] #?(:clj (UUID. high low) :cljs (uuid (impl/custom high low))))) (def zero (uuid "00000000-0000-0000-0000-000000000000")) @@ -137,6 +138,17 @@ (+ (clojure.lang.Murmur3/hashLong a) (clojure.lang.Murmur3/hashLong b))))) +;; Fake uuids generator +(def ^:private fake-ids (atom 0)) + +(defn next-fake + "When you need predictable uuids, for example when debugging a failing test, wrap the code with + (with-redefs [uuid/next uuid/next-fake] + ...tested code...)" + [] + (-> (swap! fake-ids inc) + (custom))) + ;; Commented code used for debug ;; #?(:cljs ;; (defn ^:export test-uuid