Skip to content

Commit

Permalink
Move map listener test from Jetty to core
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Oct 12, 2023
1 parent a19c97b commit 3838af6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
22 changes: 20 additions & 2 deletions ring-core/test/ring/test/websocket.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns ring.test.websocket
(:require [clojure.test :refer [deftest is testing]]
[ring.websocket :as ws]))
(:require [clojure.test :refer [deftest is]]
[ring.websocket :as ws]
[ring.websocket.protocols :as wsp]))

(deftest test-request-protocols
(is (empty? (ws/request-protocols {:headers {}})))
Expand All @@ -9,3 +10,20 @@
(is (= ["mqtt" "soap"]
(ws/request-protocols
{:headers {"sec-websocket-protocol" "mqtt, soap"}}))))

(deftest test-map-listeners
(let [listener {:on-open (fn [s] [:on-open s])
:on-message (fn [s m] [:on-message s m])
:on-pong (fn [s d] [:on-pong s d])
:on-error (fn [s e] [:on-error s e])
:on-close (fn [s c r] [:on-close s c r])}]
(is (= [:on-open :sock]
(wsp/on-open listener :sock)))
(is (= [:on-message :sock "foo"]
(wsp/on-message listener :sock "foo")))
(is (= [:on-pong :sock "data"]
(wsp/on-pong listener :sock "data")))
(is (= [:on-error :sock "err"]
(wsp/on-error listener :sock "err")))
(is (= [:on-close :sock 1000 "closed"]
(wsp/on-close listener :sock 1000 "closed")))))
19 changes: 1 addition & 18 deletions ring-jetty-adapter/test/ring/adapter/test/jetty.clj
Original file line number Diff line number Diff line change
Expand Up @@ -824,21 +824,4 @@
(Thread/sleep 100)
@(hato/close! ws)
(Thread/sleep 100)))
(is (= ["Hello" "World"] @log))))

(testing "using a map as a listener"
(let [listener {:on-open (fn [s] [:on-open s])
:on-message (fn [s m] [:on-message s m])
:on-pong (fn [s d] [:on-pong s d])
:on-error (fn [s e] [:on-error s e])
:on-close (fn [s c r] [:on-close s c r])}]
(is (= [:on-open :sock]
(wsp/on-open listener :sock)))
(is (= [:on-message :sock "foo"]
(wsp/on-message listener :sock "foo")))
(is (= [:on-pong :sock "data"]
(wsp/on-pong listener :sock "data")))
(is (= [:on-error :sock "err"]
(wsp/on-error listener :sock "err")))
(is (= [:on-close :sock 1000 "closed"]
(wsp/on-close listener :sock 1000 "closed"))))))
(is (= ["Hello" "World"] @log)))))

0 comments on commit 3838af6

Please sign in to comment.