Improve statsd test

This commit is contained in:
Michiel Borkent 2020-04-15 23:08:30 +02:00
parent 2241ce67dd
commit 9be4c7e9a9
2 changed files with 25 additions and 8 deletions

View file

@ -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

View file

@ -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)))))