multiforecast-client 0.62.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,170 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultiForecast::Client do
4
+ include_context "setup_graph"
5
+ id_keys = %w[base_uri path id service_name section_name graph_name]
6
+ graph_keys = %w[number llimit mode stype adjustval gmode color created_at ulimit description
7
+ sulimit unit sort updated_at adjust type sllimit meta md5]
8
+ complex_keys = %w[number complex created_at service_name section_name id graph_name data sumup
9
+ description sort updated_at]
10
+
11
+ context "#list_graph" do
12
+ include_context "stub_list_graph" if ENV['MOCK'] == 'on'
13
+ subject { graphs }
14
+ its(:size) { should > 0 }
15
+ id_keys.each {|key| its(:first) { should have_key(key) } }
16
+ end
17
+
18
+ context "#get_graph" do
19
+ include_context "stub_get_graph" if ENV['MOCK'] == 'on'
20
+ subject { multiforecast.get_graph(graph["path"]) }
21
+ id_keys.each {|key| it { subject[key].should == graph[key] } }
22
+ graph_keys.each {|key| it { subject.should have_key(key) } }
23
+ end
24
+
25
+ context "#post_graph" do
26
+ include_context "stub_post_graph" if ENV['MOCK'] == 'on'
27
+ include_context "stub_get_graph" if ENV['MOCK'] == 'on'
28
+ params = {
29
+ 'number' => 0,
30
+ }
31
+ subject { multiforecast.post_graph(graph["path"], params) }
32
+ it { subject["error"].should == 0 }
33
+ params.keys.each {|key| it { subject["data"][key].should == params[key] } }
34
+ end
35
+
36
+ context "#delete_graph" do
37
+ include_context "stub_post_graph" if ENV['MOCK'] == 'on'
38
+ include_context "stub_delete_graph" if ENV['MOCK'] == 'on'
39
+ let(:graph) { { 'path' => "app name/host name/delete:test" } }
40
+ before { multiforecast.post_graph(graph['path'], { 'number' => 0 }) }
41
+ subject { multiforecast.delete_graph(graph['path']) }
42
+ it { subject["error"].should == 0 }
43
+ end
44
+
45
+ context "#edit_graph" do
46
+ include_context "stub_edit_graph" if ENV['MOCK'] == 'on'
47
+ params = {
48
+ 'sort' => 19,
49
+ 'adjust' => '/',
50
+ 'adjustval' => '1000000',
51
+ 'unit' => 'sec',
52
+ 'color' => "#000000"
53
+ }
54
+ before do
55
+ @before = multiforecast.get_graph(graph["path"])
56
+ @response = multiforecast.edit_graph(graph["path"], params)
57
+ @after = multiforecast.get_graph(graph["path"])
58
+ end
59
+ it { @response["error"].should == 0 }
60
+ # @todo: how to stub @after?
61
+ unless ENV['MOCK'] == 'on'
62
+ (id_keys + graph_keys - params.keys - %w[meta md5]).each {|key| it { @after[key].should == @before[key] } }
63
+ params.keys.each {|key| it { @after[key].should == params[key] } }
64
+ end
65
+ end
66
+
67
+ describe "complex" do
68
+ describe "before create" do
69
+ include_context "let_complex"
70
+ context "#create_complex" do
71
+ include_context "stub_create_complex" if ENV['MOCK'] == 'on'
72
+ include_context "stub_delete_complex" if ENV['MOCK'] == 'on'
73
+ subject { multiforecast.create_complex(from_graphs, to_complex) }
74
+ it { subject["error"].should == 0 }
75
+ after { multiforecast.delete_complex(to_complex["path"]) }
76
+ end
77
+ end
78
+
79
+ describe "after create" do
80
+ include_context "setup_complex"
81
+ context "#get_complex" do
82
+ include_context "stub_get_complex" if ENV['MOCK'] == 'on'
83
+ subject { multiforecast.get_complex(to_complex['path']) }
84
+ complex_keys.each {|key| it { subject.should have_key(key) } }
85
+ end
86
+ end
87
+ end
88
+
89
+ describe "graph_uri" do
90
+ let(:params) do
91
+ {
92
+ 't' => 'h',
93
+ 'width' => 500,
94
+ 'height' => 300,
95
+ }
96
+ end
97
+ context "#get_graph_uri" do
98
+ subject { multiforecast.get_graph_uri(graph["path"], params) }
99
+ it_should_behave_like 'graph_uri_params'
100
+ end
101
+ context "#get_complex_uri" do
102
+ subject { multiforecast.get_complex_uri(graph["path"], params) }
103
+ it_should_behave_like 'graph_uri_params'
104
+ end
105
+ end
106
+
107
+ describe "graph_uri_fromto" do
108
+ shared_context "short_period" do
109
+ before { now = Time.now; Time.stub(:now) { now } }
110
+ let(:params) do
111
+ {
112
+ 'width' => 500,
113
+ 'height' => 300,
114
+ 'from' => Time.now - 60 * 60 * 24 * 2,
115
+ 'to' => Time.now,
116
+ }
117
+ end
118
+ end
119
+ shared_context "long_period" do
120
+ before { now = Time.now; Time.stub(:now) { now } }
121
+ let(:params) do
122
+ {
123
+ 'width' => 500,
124
+ 'height' => 300,
125
+ 'from' => (Time.now - 60 * 60 * 24 * 3).strftime("%F %T %z"),
126
+ 'to' => Time.now.strftime("%F %T %z"),
127
+ }
128
+ end
129
+ end
130
+
131
+ context "#get_graph_uri" do
132
+ subject { multiforecast_2.get_graph_uri(graph["path"], params) }
133
+ context "short_metrics is true and short period" do
134
+ let(:multiforecast_2) { multiforecast }
135
+ include_context "short_period"
136
+ it_should_behave_like 'graph_uri_short_metrics'
137
+ end
138
+ context "short_metrics is true and long period" do
139
+ let(:multiforecast_2) { multiforecast }
140
+ include_context "long_period"
141
+ it_should_behave_like 'graph_uri_long_metrics'
142
+ end
143
+ context "short_metrics is false and short period" do
144
+ let(:multiforecast_2) { multiforecast.tap{|s| s.short_metrics = false } }
145
+ include_context "short_period"
146
+ it_should_behave_like 'graph_uri_long_metrics'
147
+ end
148
+ end
149
+
150
+ context "#get_complex_uri" do
151
+ subject { multiforecast_2.get_complex_uri(graph["path"], params) }
152
+ context "short_metrics is true and short period" do
153
+ let(:multiforecast_2) { multiforecast }
154
+ include_context "short_period"
155
+ it_should_behave_like 'graph_uri_short_metrics'
156
+ end
157
+ context "short_metrics is true and long period" do
158
+ let(:multiforecast_2) { multiforecast }
159
+ include_context "long_period"
160
+ it_should_behave_like 'graph_uri_long_metrics'
161
+ end
162
+ context "short_metrics is false and short period" do
163
+ let(:multiforecast_2) { multiforecast.tap{|s| s.short_metrics = false } }
164
+ include_context "short_period"
165
+ it_should_behave_like 'graph_uri_long_metrics'
166
+ end
167
+ end
168
+ end
169
+ end
170
+
@@ -0,0 +1,152 @@
1
+ require 'spec_helper'
2
+
3
+ describe MultiForecast::ConversionRule do
4
+ include MultiForecast::ConversionRule
5
+
6
+ describe "#service_name" do
7
+ context "4 or more levels" do
8
+ let(:path) { 'a/b/c/d' }
9
+ subject { service_name(path) }
10
+ it { should == 'multiforecast' }
11
+ end
12
+
13
+ context "2 levels" do
14
+ let(:path) { 'a/b' }
15
+ subject { service_name(path) }
16
+ it { should == 'multiforecast' }
17
+ end
18
+
19
+ context "1 level" do
20
+ let(:path) { 'a' }
21
+ subject { service_name(path) }
22
+ it { should == 'multiforecast' }
23
+ end
24
+
25
+ context "3 levels (special)" do
26
+ let(:path) { 'a/b/c' }
27
+ subject { service_name(path) }
28
+ it { should == 'a' }
29
+ end
30
+ end
31
+
32
+ describe "#section_name" do
33
+ context "4 or more levels" do
34
+ let(:path) { 'a/b/c/d' }
35
+ subject { section_name(path) }
36
+ it { should == 'a%2Fb%2Fc' }
37
+ end
38
+
39
+ context "2 levels" do
40
+ let(:path) { 'a/b' }
41
+ subject { section_name(path) }
42
+ it { should == 'a' }
43
+ end
44
+
45
+ context "1 level" do
46
+ let(:path) { 'a' }
47
+ subject { section_name(path) }
48
+ it { should == '%2E' }
49
+ end
50
+
51
+ context "whitespace" do
52
+ let(:path) { 'a b/c' }
53
+ subject { section_name(path) }
54
+ it { should == 'a%20b' }
55
+ end
56
+
57
+ context "dot" do
58
+ let(:path) { 'a.b/c' }
59
+ subject { section_name(path) }
60
+ it { should == 'a%2Eb' }
61
+ end
62
+
63
+ context "3 levels (special)" do
64
+ let(:path) { 'a/b/c' }
65
+ subject { section_name(path) }
66
+ it { should == 'b' }
67
+ end
68
+ end
69
+
70
+ describe "#graph_name" do
71
+ context "4 or more levels" do
72
+ let(:path) { 'a/b/c/d' }
73
+ subject { graph_name(path) }
74
+ it { should == 'd' }
75
+ end
76
+
77
+ context "2 levels" do
78
+ let(:path) { 'a/b' }
79
+ subject { graph_name(path) }
80
+ it { should == 'b' }
81
+ end
82
+
83
+ context "1 level" do
84
+ let(:path) { 'a' }
85
+ subject { graph_name(path) }
86
+ it { should == 'a' }
87
+ end
88
+
89
+ context "whitespace" do
90
+ let(:path) { 'a/b c' }
91
+ subject { graph_name(path) }
92
+ it { should == 'b c' }
93
+ end
94
+
95
+ context "dot" do
96
+ let(:path) { 'a/b.c' }
97
+ subject { graph_name(path) }
98
+ it { should == 'b.c' }
99
+ end
100
+
101
+ context "3 levels (special)" do
102
+ let(:path) { 'a/b/c' }
103
+ subject { graph_name(path) }
104
+ it { should == 'c' }
105
+ end
106
+ end
107
+
108
+ describe "#path" do
109
+ subject { path(service_name(path1), section_name(path1), graph_name(path1)) }
110
+
111
+ context "4 or more levels" do
112
+ let(:path1) { 'a/b/c/d' }
113
+ it { should == path1 }
114
+ end
115
+
116
+ context "2 levels" do
117
+ let(:path1) { 'a/b' }
118
+ it { should == path1 }
119
+ end
120
+
121
+ context "1 level" do
122
+ let(:path1) { 'c' }
123
+ it { should == path1 }
124
+ end
125
+
126
+ context "whitespace section" do
127
+ let(:path1) { 'a b/c' }
128
+ it { should == path1 }
129
+ end
130
+
131
+ context "dot section" do
132
+ let(:path1) { 'a.b/c' }
133
+ it { should == path1 }
134
+ end
135
+
136
+ context "whitespace graph" do
137
+ let(:path1) { 'a/b c' }
138
+ it { should == path1 }
139
+ end
140
+
141
+ context "dot graph" do
142
+ let(:path1) { 'a/b.c' }
143
+ it { should == path1 }
144
+ end
145
+
146
+ context "3 levels (special)" do
147
+ let(:path1) { 'a/b/c' }
148
+ it { should == path1 }
149
+ end
150
+ end
151
+ end
152
+
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require "bundler/setup"
3
+
4
+ ENV['MOCK'] ||= 'on'
5
+ require "pry"
6
+ require 'multiforecast-client'
7
+ require 'multiforecast/shared_context'
8
+ require 'multiforecast/shared_examples'
9
+ require 'webmock/rspec'
10
+ WebMock.allow_net_connect! if ENV['MOCK'] == 'off'
11
+
12
+ ROOT = File.dirname(__FILE__)
13
+ Dir[File.expand_path("support/**/*.rb", ROOT)].each {|f| require f }
14
+
15
+ RSpec.configure do |config|
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multiforecast-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.62.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: growthforecast-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.62.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.62.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-nav
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: tapp
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Multiple GrowthForecast Client
112
+ email:
113
+ - sonots@gmail.com
114
+ executables:
115
+ - multiforecast
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .pryrc
121
+ - .rdebugrc
122
+ - .rspec
123
+ - .travis.yml
124
+ - CHANGELOG.md
125
+ - Gemfile
126
+ - LICENSE
127
+ - README.md
128
+ - Rakefile
129
+ - VERSION
130
+ - bin/multiforecast
131
+ - examples/example.rb
132
+ - lib/multiforecast-client.rb
133
+ - lib/multiforecast/cli.rb
134
+ - lib/multiforecast/client.rb
135
+ - lib/multiforecast/conversion_rule.rb
136
+ - lib/multiforecast/shared_context.rb
137
+ - lib/multiforecast/shared_context/mock.rb
138
+ - lib/multiforecast/shared_context/setup.rb
139
+ - lib/multiforecast/shared_examples.rb
140
+ - multiforecast-client.gemspec
141
+ - spec/multiforecast/client_spec.rb
142
+ - spec/multiforecast/conversion_rule_spec.rb
143
+ - spec/spec_helper.rb
144
+ homepage: https://github.com/sonots/multiforecast-client
145
+ licenses: []
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.0.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Multiple GrowthForecast Client
167
+ test_files:
168
+ - spec/multiforecast/client_spec.rb
169
+ - spec/multiforecast/conversion_rule_spec.rb
170
+ - spec/spec_helper.rb