diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index 2502cb39..bbe33abb 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -402,19 +402,11 @@ (bb nil (format "(.deleteOnExit (io/file \"%s\"))" p)) (is (false? (.exists f)))))) - (deftest yaml-test (is (str/starts-with? (bb nil "(yaml/generate-string [{:name \"John Smith\", :age 33} {:name \"Mary Smith\", :age 27}])") "-"))) -(deftest statsd-client-test - (is (= :success (bb nil " -(load-file (io/file \"test-resources\" \"babashka\" \"statsd.clj\")) -(require '[statsd-client :as c]) -(c/increment :foo) -:success")))) - ;;;; Scratch (comment diff --git a/test/babashka/udp_test.clj b/test/babashka/udp_test.clj new file mode 100644 index 00000000..5c0f3730 --- /dev/null +++ b/test/babashka/udp_test.clj @@ -0,0 +1,25 @@ +(ns babashka.udp-test + (:require [babashka.test-utils :as tu] + [clojure.test :refer [deftest is]]) + (:import [java.io StringWriter] + [java.net DatagramPacket DatagramSocket])) + +(set! *warn-on-reflection* true) + +(deftest udp-test + (let [server (DatagramSocket. 8125) + sw (StringWriter.) + fut (future + (let [buf (byte-array 1024) + packet (DatagramPacket. buf 1024) + _ (.receive server packet) + non-zero-bytes (filter #(not (zero? %)) (.getData packet)) + non-zero-bytes (byte-array non-zero-bytes)] + (binding [*out* sw] + (println (String. non-zero-bytes "UTF-8")))))] + (while (not (realized? fut)) + (tu/bb nil + "-e" "(load-file (io/file \"test-resources\" \"babashka\" \"statsd.clj\"))" + "-e" "(require '[statsd-client :as c])" + "-e" "(c/increment :foo)")) + (is (= ":foo:1|c\n" (str sw)))))