spec/app_spec.rb in fnordmetric-0.5.1 vs spec/app_spec.rb in fnordmetric-0.5.2
- old
+ new
@@ -19,10 +19,14 @@
def app
@app ||= FnordMetric::App.new({
:foospace => proc{
widget 'Blubb', nil
+
+ gauge :testgauge, :tick => 1.hour.to_i, :progressive => true
+ gauge :test3gauge, :tick => 1.hour.to_i, :three_dimensional => true
+
}
}, @opts)
end
it "should redirect to the first namespace" do
@@ -405,16 +409,72 @@
#last_response.status.should == 200
#FnordMetric::Event.last.type.should == "myevent"
#FnordMetric::Event.last.blubb.should == 42.23
end
+ end
+ describe "gauges api" do
+ before(:all) do
+ @redis.keys("fnordmetric-foospace*").each { |k| @redis.del(k) }
+ gauge_key = "fnordmetric-foospace-gauge-testgauge-#{1.hour.to_i}"
+ @redis.hset(gauge_key, 1323687600, "18")
+ @redis.hset(gauge_key, 1323691200, "23")
+ end
- end
+ it "should return the right answer for: /metric/:name?at=timestamp" do
+ get "/foospace/gauge/testgauge?at=1323691205"
+ JSON.parse(last_response.body).first.last.to_i.should == 23
+ end
- describe "metrics api" do
- # copy from _spec/app_spec.rb ?
+ it "should return the right answer for: /metric/:name?at=timestamp" do
+ get "/foospace/gauge/testgauge?at=1323691200"
+ JSON.parse(last_response.body).first.last.to_i.should == 23
+ end
+
+ it "should return the right answer for: /metric/:name?at=timestamp-timstamp" do
+ get "/foospace/gauge/testgauge?at=1323691200-1323691205"
+ JSON.parse(last_response.body).first.last.to_i.should == 18
+ end
+
+ it "should return the right answer for: /metric/:name?at=timestamp-timstamp" do
+ get "/foospace/gauge/testgauge?at=1323691201-1323695205"
+ JSON.parse(last_response.body).keys.length
+ end
+
+ it "should return the right answer for: /metric/:name?at=timestamp-timstamp" do
+ get "/foospace/gauge/testgauge?at=1323691199-1323701201"
+ JSON.parse(last_response.body).keys.length.should == 4
+ JSON.parse(last_response.body)["1323687600"].to_i.should == 18
+ JSON.parse(last_response.body)["1323691200"].to_i.should == 23
+ end
+
+ it "should return the right answer for: /metric/:name?at=timestamp-timstamp&sum=true" do
+ get "/foospace/gauge/testgauge?at=1323691199-1323701201&sum=true"
+ JSON.parse(last_response.body).keys.length.should == 1
+ JSON.parse(last_response.body)["sum"].to_i.should == 18+23
+ end
+
end
+ describe "three-dim gauges api" do
+
+ before(:all) do
+ @redis.keys("fnordmetric-foospace*").each { |k| @redis.del(k) }
+ gauge_key = "fnordmetric-foospace-gauge-test3gauge-#{1.hour.to_i}-1323691200"
+ @redis.zadd(gauge_key, 18, "fnordyblubb")
+ @redis.zadd(gauge_key, 23, "uberfoo")
+ @redis.set(gauge_key+"-count", 41)
+ end
+
+ it "should return the right answer for: /metric/:name?at=timestamp" do
+ get "/foospace/gauge/test3gauge?at=1323691205"
+ JSON.parse(last_response.body)["count"].to_i.should == 41
+ JSON.parse(last_response.body)["values"].length.should == 2
+ JSON.parse(last_response.body)["values"][0].should == ["uberfoo", "23"]
+ JSON.parse(last_response.body)["values"][1].should == ["fnordyblubb", "18"]
+ end
+
+ end
end
\ No newline at end of file