From c04de14516621aa90e42ff9beba8c3bb78524754 Mon Sep 17 00:00:00 2001 From: niten Date: Sun, 8 Jun 2025 10:27:17 -0700 Subject: [PATCH] Added some testing --- src/milquetoast/api.clj | 18 ++++++------- src/milquetoast/core.clj | 21 ++++++++++++++-- test/milquetoast/api_test.clj | 38 ---------------------------- test/milquetoast/client_test.clj | 43 -------------------------------- test/milquetoast/core_test.clj | 13 ---------- test/milquetoast/utils_test.clj | 3 ++- 6 files changed, 30 insertions(+), 106 deletions(-) delete mode 100644 test/milquetoast/api_test.clj delete mode 100644 test/milquetoast/client_test.clj delete mode 100644 test/milquetoast/core_test.clj diff --git a/src/milquetoast/api.clj b/src/milquetoast/api.clj index 9aa0d9e..d949c34 100644 --- a/src/milquetoast/api.clj +++ b/src/milquetoast/api.clj @@ -1,7 +1,7 @@ (ns milquetoast.api (:require [clojure.core.async :refer [chan MilquetoastClient client (atom []) verbose))) (defn create-json-client @@ -132,3 +146,6 @@ :or {verbose false}}] (let [client (create-client broker-uri username password :verbose verbose)] (->MilquetoastJsonClient client))) + +(def milquetoast-client? (partial instance? MilquetoastClient)) +(def milquetoast-json-client? (partial instance? MilquetoastJsonClient)) diff --git a/test/milquetoast/api_test.clj b/test/milquetoast/api_test.clj deleted file mode 100644 index eec8667..0000000 --- a/test/milquetoast/api_test.clj +++ /dev/null @@ -1,38 +0,0 @@ -(ns milquetoast.api-test - (:require [clojure.test :refer :all] - [milquetoast.api :as api])) - -(deftest test-send! - (testing "send!" - ;; TODO: Add your test implementation here - )) - -(deftest test-get! - (testing "get!" - ;; TODO: Add your test implementation here - )) - -(deftest test-get-raw! - (testing "get-raw!" - ;; TODO: Add your test implementation here - )) - -(deftest test-open-channel! - (testing "open-channel!" - ;; TODO: Add your test implementation here - )) - -(deftest test-subscribe! - (testing "subscribe!" - ;; TODO: Add your test implementation here - )) - -(deftest test-connect! - (testing "connect!" - ;; TODO: Add your test implementation here - )) - -(deftest test-connect-json! - (testing "connect-json!" - ;; TODO: Add your test implementation here - )) diff --git a/test/milquetoast/client_test.clj b/test/milquetoast/client_test.clj deleted file mode 100644 index 8fb7631..0000000 --- a/test/milquetoast/client_test.clj +++ /dev/null @@ -1,43 +0,0 @@ -(ns milquetoast.client-test - (:require [milquetoast.client :as sut] - [clojure.test :as t] - [org.eclipse.paho.client.mqttv3 MqttClient])) - -(t/deftest test-create-mqtt-client! - (t/testing "create-mqtt-client! returns an instance of MqttClient" - (t/is (instance? MqttClient (sut/create-mqtt-client! :broker-uri "tcp://localhost:1883"))))) - -(t/deftest test-retry-attempt - (t/testing "retry-attempt retries function execution upon RuntimeException" - (let [attempt-count (atom 0)] - (sut/retry-attempt false - (fn [] - (swap! attempt-count inc) - (when (< @attempt-count 3) - (throw (RuntimeException. "Test exception")))) - #(println "Reconnecting...")) - (t/is (= 3 @attempt-count))))) - -(t/deftest test-create-message - (t/testing "create-message creates an MQTT message with the provided options" - (let [msg (sut/create-message "test" {:qos 2 :retain true})] - (t/is (= 2 (.getQos msg))) - (t/is (.isRetained msg))))) - -(t/deftest test-parse-message - (t/testing "parse-message parses an MQTT message into a map" - (let [mqtt-msg (sut/create-message "test" {:qos 2 :retain true}) - parsed-msg (sut/parse-message mqtt-msg)] - (t/is (= 2 (:qos parsed-msg))) - (t/is (:retained parsed-msg))))) - -(t/deftest test-parallelism - (t/testing "parallelism returns the number of available processors plus one" - (t/is (= (inc (.availableProcessors (Runtime/getRuntime))) (sut/parallelism))))) - -(t/deftest test-json-parse-message - (t/testing "json-parse-message parses the payload of an MQTT message into a map and adds a timestamp" - (let [mqtt-msg (sut/create-message "{\"test\": \"value\"}" {:qos 2 :retain true}) - parsed-msg (sut/json-parse-message (sut/parse-message mqtt-msg))] - (t/is (= "value" (:test (:payload parsed-msg)))) - (t/is (instance? java.time.Instant (:timestamp parsed-msg)))))) diff --git a/test/milquetoast/core_test.clj b/test/milquetoast/core_test.clj deleted file mode 100644 index 3dbee68..0000000 --- a/test/milquetoast/core_test.clj +++ /dev/null @@ -1,13 +0,0 @@ -(ns milquetoast.core-test - (:require [clojure.test :refer [deftest is testing]] - [milquetoast.core :as core :refer [MilquetoastClient MilquetoastJsonClient]])) - -(deftest test-create-client - (testing "create-client" - (let [client (core/create-client "tcp://localhost:1883" "username" "password")] - (is (instance? MilquetoastClient client))))) - -(deftest test-create-json-client - (testing "create-json-client" - (let [client (core/create-json-client "tcp://localhost:1883" "username" "password")] - (is (instance? MilquetoastJsonClient client))))) diff --git a/test/milquetoast/utils_test.clj b/test/milquetoast/utils_test.clj index 5a350e0..87c0d22 100644 --- a/test/milquetoast/utils_test.clj +++ b/test/milquetoast/utils_test.clj @@ -1,5 +1,6 @@ (ns milquetoast.utils-test - (:require [clojure.test :refer :all] + (:require [clojure.test :refer [deftest is testing]] + [clojure.core.async :refer [chan >!!