batsd-dash 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,86 +0,0 @@
1
- require 'helper'
2
-
3
- describe BatsdDash::App do
4
- before do
5
- json = { 'interval' => 10, 'counters:a.b' => [] }
6
-
7
- BatsdDash::ConnectionPool::Client.any_instance.stubs(:sync).returns(true)
8
- BatsdDash::ConnectionPool::Client.any_instance.stubs(:unbind).returns(true)
9
-
10
- EM::Synchrony::ConnectionPool.any_instance.stubs(:async_values).yields(json)
11
- end
12
-
13
- describe 'params helper' do
14
- before do
15
- header 'Accept', 'application/json'
16
- end
17
-
18
- describe 'metrics param' do
19
- it 'returns error on nil metrics' do
20
- get '/counters'
21
-
22
- last_response.status.must_equal 400
23
- last_response.body.must_include 'error'
24
- end
25
-
26
- it 'returns error on empty metrics' do
27
- get '/counters?metrics[]='
28
-
29
- last_response.status.must_equal 400
30
- last_response.body.must_include 'error'
31
- end
32
-
33
- it 'valid with single metrics param' do
34
- get '/counters?metrics=a.b'
35
-
36
- last_response.status.must_equal 200
37
- last_response.body.wont_be_empty
38
-
39
- json_response[:metrics].size.must_equal 1
40
- end
41
-
42
- it 'valid with multiple metrics param' do
43
- # same statistic is used cause the stub method is rather limited
44
- get '/counters?metrics[]=a.b&metrics[]=a.b'
45
-
46
- last_response.status.must_equal 200
47
- last_response.body.wont_be_empty
48
-
49
- json_response[:metrics].size.must_equal 2
50
- end
51
- end
52
-
53
- describe 'range params' do
54
- before do
55
- @start = Time.now.to_i - 86000
56
- @stop = Time.now.to_i
57
- end
58
-
59
- it 'returns error without stop param' do
60
- get "/counters?metrics[]=a.b&start=#{@start}"
61
-
62
- last_response.status.must_equal 400
63
- last_response.body.must_include 'error'
64
- end
65
-
66
- it 'returns error without start param' do
67
- get "/counters?metrics[]=a.b&stop=#{@stop}"
68
-
69
- last_response.status.must_equal 400
70
- last_response.body.must_include 'error'
71
- end
72
-
73
- it 'returns error on invalid range' do
74
- get "/counters?metrics[]=a.b&start=#{@stop}&stop=#{@start}"
75
-
76
- last_response.status.must_equal 400
77
- last_response.body.must_include 'error'
78
-
79
- get '/counters?metrics[]=a.b&start=-2&stop=-1'
80
-
81
- last_response.status.must_equal 400
82
- last_response.body.must_include 'error'
83
- end
84
- end
85
- end
86
- end