Skip to content

Commit

Permalink
begin adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor McArthur committed Jan 18, 2014
1 parent 08c72f4 commit 26c72d4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
[com.amazonaws/aws-java-sdk "1.6.3"]
[overtone/at-at "1.2.0"]
[clj-time "0.6.0"]]
:profiles {:dev {:dependencies [[midje "1.5.1"]]}}
:main cmcarthur.doppler.core)
5 changes: 3 additions & 2 deletions src/cmcarthur/doppler/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
reducer (:reducer config)
metrics (:metrics config)
output (:output config)
value-to-push (apply reducer (map (comp mapper cloudwatch/get-metric) metrics))]
(cloudwatch/push-metric output value-to-push)))
value-to-push (reduce reducer (map (comp mapper cloudwatch/get-metric) metrics))]
(cloudwatch/push-metric output value-to-push)
value-to-push))

(defn generate-metrics-from-config
[config]
Expand Down
30 changes: 30 additions & 0 deletions test/cmcarthur/doppler/core_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns cmcarthur.doppler.core-test
(:use midje.sweet)
(:require [cmcarthur.doppler.core :refer :all]
[cmcarthur.doppler.cloudwatch :as cloudwatch]))

(facts "generate-metric-results"
(prerequisites
(cloudwatch/get-metric 1) => [{:average 1 :sum 1 :time nil}]
(cloudwatch/get-metric 2) => [{:average 2 :sum 2 :time nil}]
(cloudwatch/push-metric anything anything) => nil)
(fact "uses map-reduce"
(generate-metric-results {:mapper (comp :average first)
:reducer +
:metrics [1 2]
:output nil}) => 3)
(fact "maintains ordering"
(generate-metric-results {:mapper (comp :average first)
:reducer -
:metrics [1 2]
:output nil}) => -1)
(fact "can handle more than two metrics"
(generate-metric-results {:mapper (comp :average first)
:reducer -
:metrics [1 2 2]
:output nil}) => -3)
(fact "works with custom reducers"
(generate-metric-results {:mapper (comp :average first)
:reducer (fn [x y] (+ x y))
:metrics [1 2 2]
:output nil}) => 5))
7 changes: 0 additions & 7 deletions test/doppler/core_test.clj

This file was deleted.

0 comments on commit 26c72d4

Please sign in to comment.