From ceaae21dbe0113a3d8d429225f5245db4c14e2a0 Mon Sep 17 00:00:00 2001 From: Aphyr Date: Wed, 2 Jan 2013 18:58:47 -0800 Subject: [PATCH] Require values and names in gauges and counters before submission. --- src/clj_librato/metrics.clj | 4 ++++ test/clj_librato/metrics_test.clj | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/clj_librato/metrics.clj b/src/clj_librato/metrics.clj index 2c0e45b..b27c510 100644 --- a/src/clj_librato/metrics.clj +++ b/src/clj_librato/metrics.clj @@ -47,6 +47,10 @@ (defn collate [user api-key gauges counters] "Posts a set of gauges and counters." + (assert (every? :name gauges)) + (assert (every? :name counters)) + (assert (every? :value gauges)) + (assert (every? :value counters)) (client/post (uri "metrics") (request user api-key {} {:gauges gauges :counters counters}))) diff --git a/test/clj_librato/metrics_test.clj b/test/clj_librato/metrics_test.clj index 9071c92..ec3a1d0 100644 --- a/test/clj_librato/metrics_test.clj +++ b/test/clj_librato/metrics_test.clj @@ -22,6 +22,20 @@ {"hello_there" [{"tiny_kitten" 3}]}))) (deftest collate-test + (testing "reject nil names" + (is (thrown? java.lang.AssertionError + (collate user apikey [{:name nil}] []))) + (is (thrown? java.lang.AssertionError + (collate user apikey [] [{:name nil}])))) + + (testing "reject nil values" + (is (thrown? java.lang.AssertionError + (collate user apikey [{:name "foo" + :value nil}] []))) + (is (thrown? java.lang.AssertionError + (collate user apikey [] [{:name "foo" + :value nil}])))) + (testing "gauge" (let [gauge {:name "test.gauge" :source "clj-librato"