Skip to content

Commit

Permalink
Require values and names in gauges and counters before submission.
Browse files Browse the repository at this point in the history
  • Loading branch information
aphyr committed Jan 3, 2013
1 parent b472fdf commit ceaae21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/clj_librato/metrics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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})))

Expand Down
14 changes: 14 additions & 0 deletions test/clj_librato/metrics_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ceaae21

Please sign in to comment.