Skip to content

Commit

Permalink
test: add rq-utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
J0sueTM committed Jul 5, 2024
1 parent 3717d5f commit 55b94e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/com/moclojer/rq/utils.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns com.moclojer.rq.utils)

(defn- pattern->str
"Adapts given pattern keyword to a know internal pattern. Raises
an exception if invalid."
[pattern]
(let [patterns {:none ""
:rq "rq:"
Expand All @@ -19,14 +21,3 @@
(defn unpack-pattern
[pattern queue-name]
(subs queue-name (count (pattern->str pattern))))

(comment
(pack-pattern :rq "my-queue")
;; => "rq:my-queue"

(pack-pattern :pending "foobar")
;; => "rq:pending:foobar"

(unpack-pattern :pending "rq:pending:foobar")
;; => "foobar"
)
15 changes: 15 additions & 0 deletions test/com/moclojer/rq/utils_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns com.moclojer.rq.utils-test
(:require
[clojure.test :as t]
[com.moclojer.rq.utils :as utils]))

(t/deftest pattern->str-test
[(t/is "my-queue" (utils/pack-pattern :none "my-queue"))
(t/is "rq:my-queue" (utils/pack-pattern :rq "my-queue"))
(t/is "rq:pubsub:my-queue" (utils/pack-pattern :pubsub "my-queue"))
(t/is "rq:pubsub:pending:my-queue" (utils/pack-pattern :pending "my-queue"))]

[(t/is "my-queue" (utils/unpack-pattern :none "my-queue"))
(t/is "my-queue" (utils/unpack-pattern :rq "rq:my-queue"))
(t/is "my-queue" (utils/unpack-pattern :pubsub "rq:pubsub:my-queue"))
(t/is "my-queue" (utils/unpack-pattern :pending "rq:pubsub:pending:my-queue"))])

0 comments on commit 55b94e6

Please sign in to comment.