growthforecast-client 0.0.6 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/examples/edit_graph.rb +1 -0
- data/lib/growthforecast/cli.rb +2 -2
- data/lib/growthforecast/client.rb +87 -17
- data/spec/growthforecast/client_spec.rb +55 -56
- data/spec/spec_helper.rb +20 -1
- data/spec/support/mock.rb +84 -34
- data/spec/support/setup.rb +38 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e380347aae163347f8aff0e1cfa188113cc3350
|
4
|
+
data.tar.gz: 4a82887db1bd53783f3132ad1fbf50d86a491296
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98882b9370b43b92a4ec1045a3f27f8d2c2b0a3a9408e0f0d2f45551d9336e2a98c616509dbf1be1c791dcfba69bc7bea58b20235829753e5bc307b310ae97fd
|
7
|
+
data.tar.gz: 5217464da3ac661d186abe1e615cdcf16fe5aa1849e4226053bdf572f07a67276182b6359fc04b182645a4058457be7b772017e84f43fa918414043fefc804b3
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# GrowthForecast Client [](http://travis-ci.org/sonots/growthforecast-client) [](https://gemnasium.com/sonots/growthforecast-client)
|
2
2
|
|
3
|
-
testing ruby: 1.9.3; GrowthForecast:
|
3
|
+
testing ruby: 1.9.2, 1.9.3, 2.0.0; GrowthForecast: >= 0.62 (Jun 27, 2013 released)
|
4
4
|
|
5
5
|
## About GrowthForecast Client
|
6
6
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.62.0
|
data/examples/edit_graph.rb
CHANGED
@@ -6,6 +6,7 @@ require 'growthforecast-client'
|
|
6
6
|
|
7
7
|
# Create a GrowthForecast Client, given he base URI of GrowthForecast
|
8
8
|
client = GrowthForecast::Client.new('http://localhost:5125')
|
9
|
+
client.debug_dev = STDOUT # debug print the http requests and responses
|
9
10
|
|
10
11
|
# configure colors of graphs whose names are as belows:
|
11
12
|
graph_colors = {
|
data/lib/growthforecast/cli.rb
CHANGED
@@ -35,12 +35,12 @@ class GrowthForecast::CLI < Thor
|
|
35
35
|
|
36
36
|
no_tasks do
|
37
37
|
def e(str)
|
38
|
-
|
38
|
+
CGI.escape(str).gsub('+', '%20') if str
|
39
39
|
end
|
40
40
|
|
41
41
|
def split_path(path)
|
42
42
|
path = path.gsub(/.*list\//, '').gsub(/.*view_graph\//, '')
|
43
|
-
path.split('/').map {|p|
|
43
|
+
path.split('/').map {|p| CGI.unescape(p.gsub('%20', '+')) }
|
44
44
|
end
|
45
45
|
|
46
46
|
def client(uri)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
require 'httpclient'
|
3
3
|
require 'json'
|
4
|
-
require '
|
4
|
+
require 'cgi'
|
5
5
|
require 'pp'
|
6
6
|
|
7
7
|
module GrowthForecast
|
@@ -12,6 +12,7 @@ module GrowthForecast
|
|
12
12
|
class Client
|
13
13
|
attr_accessor :debug
|
14
14
|
attr_accessor :client
|
15
|
+
attr_reader :debug_dev
|
15
16
|
attr_reader :base_uri
|
16
17
|
|
17
18
|
# @param [String] base_uri The base uri of GrowthForecast
|
@@ -23,6 +24,12 @@ module GrowthForecast
|
|
23
24
|
@client ||= HTTPClient.new
|
24
25
|
end
|
25
26
|
|
27
|
+
# set the `debug_dev` attribute of HTTPClient
|
28
|
+
# @param [IO] debug_dev such as STDOUT
|
29
|
+
def debug_dev=(debug_dev)
|
30
|
+
client.debug_dev = debug_dev
|
31
|
+
end
|
32
|
+
|
26
33
|
def last_response
|
27
34
|
@res
|
28
35
|
end
|
@@ -121,6 +128,42 @@ module GrowthForecast
|
|
121
128
|
services.keys
|
122
129
|
end
|
123
130
|
|
131
|
+
# Post parameters to a graph, POST /api/:service_name/:section_name/:graph_name
|
132
|
+
# @param [String] service_name
|
133
|
+
# @param [String] section_name
|
134
|
+
# @param [String] graph_name
|
135
|
+
# @param [Hash] params The POST parameters. See #get_graph
|
136
|
+
# @return [Hash] the error code and graph property
|
137
|
+
# @example
|
138
|
+
#{"error"=>0,
|
139
|
+
#"data"=>{
|
140
|
+
# "number"=>1,
|
141
|
+
# "llimit"=>-1000000000,
|
142
|
+
# "mode"=>"gauge",
|
143
|
+
# "stype"=>"AREA",
|
144
|
+
# "adjustval"=>"1",
|
145
|
+
# "meta"=>"",
|
146
|
+
# "service_name"=>"test",
|
147
|
+
# "gmode"=>"gauge",
|
148
|
+
# "color"=>"#cc6633",
|
149
|
+
# "created_at"=>"2013/02/02 00:41:11",
|
150
|
+
# "section_name"=>"hostname",
|
151
|
+
# "ulimit"=>1000000000,
|
152
|
+
# "id"=>21,
|
153
|
+
# "graph_name"=>"<4sec_count",
|
154
|
+
# "description"=>"",
|
155
|
+
# "sulimit"=>100000,
|
156
|
+
# "unit"=>"",
|
157
|
+
# "sort"=>0,
|
158
|
+
# "updated_at"=>"2013/02/02 02:32:10",
|
159
|
+
# "adjust"=>"*",
|
160
|
+
# "type"=>"AREA",
|
161
|
+
# "sllimit"=>-100000,
|
162
|
+
# "md5"=>"3c59dc048e8850243be8079a5c74d079"}}
|
163
|
+
def post_graph(service_name, section_name, graph_name, params)
|
164
|
+
post_query("/api/#{e service_name}/#{e section_name}/#{e graph_name}", params)
|
165
|
+
end
|
166
|
+
|
124
167
|
# Get the propety of a graph, GET /api/:service_name/:section_name/:graph_name
|
125
168
|
# @param [String] service_name
|
126
169
|
# @param [String] section_name
|
@@ -185,15 +228,6 @@ module GrowthForecast
|
|
185
228
|
get_json("/json/graph/#{id}")
|
186
229
|
end
|
187
230
|
|
188
|
-
# Post parameters to a graph, POST /api/:service_name/:section_name/:graph_name
|
189
|
-
# @param [String] service_name
|
190
|
-
# @param [String] section_name
|
191
|
-
# @param [String] graph_name
|
192
|
-
# @param [Hash] params The POST parameters. See #get_graph
|
193
|
-
def post_graph(service_name, section_name, graph_name, params)
|
194
|
-
post_query("/api/#{e service_name}/#{e section_name}/#{e graph_name}", params)
|
195
|
-
end
|
196
|
-
|
197
231
|
# Delete a graph, POST /delete/:service_name/:section_name/:graph_name
|
198
232
|
# @param [String] service_name
|
199
233
|
# @param [String] section_name
|
@@ -202,6 +236,12 @@ module GrowthForecast
|
|
202
236
|
post_query("/delete/#{e service_name}/#{e section_name}/#{e graph_name}")
|
203
237
|
end
|
204
238
|
|
239
|
+
# Delete a graph, POST /json/delete/graph/:id
|
240
|
+
# @param [String] id
|
241
|
+
def delete_graph_by_id(id)
|
242
|
+
post_query("/json/delete/graph/#{id}")
|
243
|
+
end
|
244
|
+
|
205
245
|
# Update the property of a graph, /json/edit/graph/:id
|
206
246
|
# @param [String] service_name
|
207
247
|
# @param [String] section_name
|
@@ -268,10 +308,43 @@ module GrowthForecast
|
|
268
308
|
:sort => to_complex["sort"],
|
269
309
|
:data => graph_data
|
270
310
|
}
|
271
|
-
|
272
311
|
post_json('/json/create/complex', post_params)
|
273
312
|
end
|
274
313
|
|
314
|
+
# Get the propety of a complex graph, GET /json/complex/:service_name/:section_name/:graph_name
|
315
|
+
# @param [String] service_name
|
316
|
+
# @param [String] section_name
|
317
|
+
# @param [String] graph_name
|
318
|
+
# @return [Hash] the graph property
|
319
|
+
# @version 0.70 or more
|
320
|
+
# @example
|
321
|
+
# {"number"=>0,
|
322
|
+
# "complex"=>true,
|
323
|
+
# "created_at"=>"2013/05/20 15:08:28",
|
324
|
+
# "service_name"=>"app name",
|
325
|
+
# "section_name"=>"host name",
|
326
|
+
# "id"=>18,
|
327
|
+
# "graph_name"=>"complex graph test",
|
328
|
+
# "data"=>
|
329
|
+
# [{"gmode"=>"gauge", "stack"=>false, "type"=>"AREA", "graph_id"=>218},
|
330
|
+
# {"gmode"=>"gauge", "stack"=>true, "type"=>"AREA", "graph_id"=>217}],
|
331
|
+
# "sumup"=>false,
|
332
|
+
# "description"=>"complex graph test",
|
333
|
+
# "sort"=>10,
|
334
|
+
# "updated_at"=>"2013/05/20 15:08:28"}
|
335
|
+
def get_complex(service_name, section_name, graph_name)
|
336
|
+
get_json("/json/complex/#{e service_name}/#{e section_name}/#{e graph_name}")
|
337
|
+
end
|
338
|
+
|
339
|
+
# Get the propety of a complex graph, GET /json/complex/:id
|
340
|
+
# @param [String] id
|
341
|
+
# @return [Hash] the graph property
|
342
|
+
# @version 0.70 or more
|
343
|
+
# @example See #get_complex
|
344
|
+
def get_complex_by_id(id)
|
345
|
+
get_json("/json/complex/#{id}")
|
346
|
+
end
|
347
|
+
|
275
348
|
# Delete a complex graph
|
276
349
|
#
|
277
350
|
# This is a helper method of GrowthForecast API to find complex graph id and call delete_complex_by_id
|
@@ -284,10 +357,7 @@ module GrowthForecast
|
|
284
357
|
# {"error"=>0} #=> Success
|
285
358
|
# {"error"=>1} #=> Error
|
286
359
|
def delete_complex(service_name, section_name, graph_name)
|
287
|
-
|
288
|
-
complex = complex_graphs.select {|g| g["service_name"] == service_name and g["section_name"] == section_name and g["graph_name"] == graph_name }
|
289
|
-
raise NotFound if complex.empty?
|
290
|
-
delete_complex_by_id(complex.first["id"])
|
360
|
+
post_query("/json/delete/complex/#{e service_name}/#{e section_name}/#{e graph_name}")
|
291
361
|
end
|
292
362
|
|
293
363
|
# Delete a complex graph, /delete_complex/:complex_id
|
@@ -304,7 +374,7 @@ module GrowthForecast
|
|
304
374
|
private
|
305
375
|
|
306
376
|
def e(str)
|
307
|
-
|
377
|
+
CGI.escape(str).gsub('+', '%20') if str
|
308
378
|
end
|
309
379
|
|
310
380
|
def handle_error(res)
|
@@ -320,7 +390,7 @@ module GrowthForecast
|
|
320
390
|
end
|
321
391
|
|
322
392
|
def error_message(res)
|
323
|
-
"status:#{res.status}\turi:#{res.http_header.request_uri.to_s}"
|
393
|
+
"status:#{res.status}\turi:#{res.http_header.request_uri.to_s}\tmessage:#{res.body}"
|
324
394
|
end
|
325
395
|
|
326
396
|
# GrowthForecast's /json/edit/graph API requires all parameters to update, thus
|
@@ -1,31 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
shared_context "setup_growthforecast_client" do
|
4
|
-
before(:all) { @client = GrowthForecast::Client.new('http://localhost:5125') }
|
5
|
-
|
6
|
-
include_context "stub_list_graph" if ENV['MOCK'] == 'on'
|
7
|
-
let(:graphs) { @client.list_graph }
|
8
|
-
let(:graph) { graphs.first }
|
9
|
-
|
10
|
-
include_context "stub_post_graph" if ENV['MOCK'] == 'on'
|
11
|
-
include_context "stub_delete_graph" if ENV['MOCK'] == 'on'
|
12
|
-
before(:all) {
|
13
|
-
@client.delete_graph("app name", "host name", "<1sec count") rescue nil
|
14
|
-
@client.delete_graph("app name", "host name", "<2sec count") rescue nil
|
15
|
-
@client.post_graph("app name", "host name", "<1sec count", { 'number' => 0 }) rescue nil
|
16
|
-
@client.post_graph("app name", "host name", "<2sec count", { 'number' => 0 }) rescue nil
|
17
|
-
}
|
18
|
-
after(:all) {
|
19
|
-
@client.delete_graph("app name", "host name", "<1sec count") rescue nil
|
20
|
-
@client.delete_graph("app name", "host name", "<2sec count") rescue nil
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
3
|
describe GrowthForecast::Client do
|
25
4
|
include_context "setup_growthforecast_client"
|
26
5
|
id_keys = %w[id service_name section_name graph_name]
|
27
6
|
graph_keys = %w[number llimit mode stype adjustval gmode color created_at ulimit description
|
28
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]
|
29
10
|
|
30
11
|
context "#list_graph" do
|
31
12
|
include_context "stub_list_graph" if ENV['MOCK'] == 'on'
|
@@ -36,7 +17,7 @@ describe GrowthForecast::Client do
|
|
36
17
|
|
37
18
|
context "#list_section" do
|
38
19
|
include_context "stub_list_graph" if ENV['MOCK'] == 'on'
|
39
|
-
subject {
|
20
|
+
subject { client.list_section }
|
40
21
|
its(:size) { should > 0 }
|
41
22
|
its(:class) { should == Hash }
|
42
23
|
it { subject.each {|service_name, sections| sections.size.should > 0 } }
|
@@ -44,21 +25,21 @@ describe GrowthForecast::Client do
|
|
44
25
|
|
45
26
|
context "#list_service" do
|
46
27
|
include_context "stub_list_graph" if ENV['MOCK'] == 'on'
|
47
|
-
subject {
|
28
|
+
subject { client.list_service }
|
48
29
|
its(:size) { should > 0 }
|
49
30
|
its(:class) { should == Array }
|
50
31
|
end
|
51
32
|
|
52
33
|
context "#get_graph" do
|
53
34
|
include_context "stub_get_graph" if ENV['MOCK'] == 'on'
|
54
|
-
subject {
|
35
|
+
subject { client.get_graph(graph["service_name"], graph["section_name"], graph["graph_name"]) }
|
55
36
|
id_keys.each {|key| it { subject[key].should == graph[key] } }
|
56
37
|
graph_keys.each {|key| it { subject.should have_key(key) } }
|
57
38
|
end
|
58
39
|
|
59
40
|
context "#get_graph_by_id" do
|
60
41
|
include_context "stub_get_graph_by_id" if ENV['MOCK'] == 'on'
|
61
|
-
subject {
|
42
|
+
subject { client.get_graph_by_id(graph["id"]) }
|
62
43
|
id_keys.each {|key| it { subject[key].should == graph[key] } }
|
63
44
|
# this is the behavior of GrowthForecast API
|
64
45
|
(graph_keys - %w[meta md5]).each {|key| it { subject.should have_key(key) } }
|
@@ -70,7 +51,7 @@ describe GrowthForecast::Client do
|
|
70
51
|
params = {
|
71
52
|
'number' => 0,
|
72
53
|
}
|
73
|
-
subject {
|
54
|
+
subject { client.post_graph(graph["service_name"], graph["section_name"], graph["graph_name"], params) }
|
74
55
|
it { subject["error"].should == 0 }
|
75
56
|
params.keys.each {|key| it { subject["data"][key].should == params[key] } }
|
76
57
|
end
|
@@ -78,6 +59,13 @@ describe GrowthForecast::Client do
|
|
78
59
|
context "#delete_graph" do
|
79
60
|
include_context "stub_post_graph" if ENV['MOCK'] == 'on'
|
80
61
|
include_context "stub_delete_graph" if ENV['MOCK'] == 'on'
|
62
|
+
before { client.post_graph(graph['service_name'], graph['section_name'], graph['graph_name'], { 'number' => 0 }) }
|
63
|
+
subject { client.delete_graph(graph['service_name'], graph['section_name'], graph['graph_name']) }
|
64
|
+
it { subject["error"].should == 0 }
|
65
|
+
end
|
66
|
+
|
67
|
+
context "#delete_graph_by_id" do
|
68
|
+
include_context "stub_post_graph" if ENV['MOCK'] == 'on'
|
81
69
|
let(:graph) {
|
82
70
|
{
|
83
71
|
"service_name" => "app name",
|
@@ -85,8 +73,12 @@ describe GrowthForecast::Client do
|
|
85
73
|
"graph_name" => "<1sec count",
|
86
74
|
}
|
87
75
|
}
|
88
|
-
|
89
|
-
|
76
|
+
let(:id) do
|
77
|
+
ret = client.post_graph(graph['service_name'], graph['section_name'], graph['graph_name'], { 'number' => 0 })
|
78
|
+
ret["data"]["id"]
|
79
|
+
end
|
80
|
+
include_context "stub_delete_graph_by_id" if ENV['MOCK'] == 'on'
|
81
|
+
subject { client.delete_graph_by_id(id) }
|
90
82
|
it { subject["error"].should == 0 }
|
91
83
|
end
|
92
84
|
|
@@ -100,10 +92,10 @@ describe GrowthForecast::Client do
|
|
100
92
|
'unit' => 'sec',
|
101
93
|
'color' => "#000000"
|
102
94
|
}
|
103
|
-
before
|
104
|
-
@before =
|
105
|
-
@response =
|
106
|
-
@after =
|
95
|
+
before do
|
96
|
+
@before = client.get_graph(graph["service_name"], graph["section_name"], graph["graph_name"])
|
97
|
+
@response = client.edit_graph(graph["service_name"], graph["section_name"], graph["graph_name"], params)
|
98
|
+
@after = client.get_graph(graph["service_name"], graph["section_name"], graph["graph_name"])
|
107
99
|
end
|
108
100
|
it { @response["error"].should == 0 }
|
109
101
|
# @todo: how to stub @after?
|
@@ -120,10 +112,10 @@ describe GrowthForecast::Client do
|
|
120
112
|
'number' => 0,
|
121
113
|
'mode' => 'count',
|
122
114
|
}
|
123
|
-
before
|
124
|
-
@before =
|
125
|
-
@response =
|
126
|
-
@after =
|
115
|
+
before do
|
116
|
+
@before = client.get_graph(graph["service_name"], graph["section_name"], graph["graph_name"])
|
117
|
+
@response = client.edit_graph(graph["service_name"], graph["section_name"], graph["graph_name"], params)
|
118
|
+
@after = client.get_graph(graph["service_name"], graph["section_name"], graph["graph_name"])
|
127
119
|
end
|
128
120
|
params.keys.each {|key| it { @after[key].should == @before[key] } }
|
129
121
|
end
|
@@ -132,29 +124,35 @@ describe GrowthForecast::Client do
|
|
132
124
|
context "#create_complex" do
|
133
125
|
include_context "stub_create_complex" if ENV['MOCK'] == 'on'
|
134
126
|
include_context "stub_delete_complex" if ENV['MOCK'] == 'on'
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
127
|
+
subject { client.create_complex(from_graphs, to_complex) }
|
128
|
+
it { subject["error"].should == 0 }
|
129
|
+
after { client.delete_complex(to_complex["service_name"], to_complex["section_name"], to_complex["graph_name"]) }
|
130
|
+
end
|
131
|
+
|
132
|
+
context "#get_complex" do
|
133
|
+
include_context "stub_create_complex" if ENV['MOCK'] == 'on'
|
134
|
+
include_context "stub_get_complex" if ENV['MOCK'] == 'on'
|
135
|
+
include_context "stub_delete_complex" if ENV['MOCK'] == 'on'
|
136
|
+
before { client.create_complex(from_graphs, to_complex) }
|
137
|
+
subject { client.get_complex(to_complex["service_name"], to_complex["section_name"], to_complex["graph_name"]) }
|
138
|
+
complex_keys.each {|key| it { subject.should have_key(key) } }
|
139
|
+
after { client.delete_complex(to_complex["service_name"], to_complex["section_name"], to_complex["graph_name"]) }
|
140
|
+
end
|
141
|
+
|
142
|
+
context "#get_complex_by_id" do
|
143
|
+
include_context "stub_create_complex" if ENV['MOCK'] == 'on'
|
144
|
+
include_context "stub_get_complex" if ENV['MOCK'] == 'on'
|
145
|
+
before { client.create_complex(from_graphs, to_complex) }
|
146
|
+
let(:id) { client.get_complex(to_complex["service_name"], to_complex["section_name"], to_complex["graph_name"])["id"] }
|
147
|
+
include_context "stub_get_complex_by_id" if ENV['MOCK'] == 'on'
|
148
|
+
include_context "stub_delete_complex_by_id" if ENV['MOCK'] == 'on'
|
149
|
+
subject { client.get_complex_by_id(id) }
|
150
|
+
complex_keys.each {|key| it { subject.should have_key(key) } }
|
151
|
+
after { client.delete_complex_by_id(id) }
|
155
152
|
end
|
156
153
|
|
157
154
|
describe 'http://blog.64p.org/?page=1366971426' do
|
155
|
+
before { @client ||= client }
|
158
156
|
context "#client=" do
|
159
157
|
before { @client.client = HTTPClient.new(agent_name: 'TestAgent/0.1') }
|
160
158
|
it { @client.client.agent_name.should == 'TestAgent/0.1' }
|
@@ -162,6 +160,7 @@ describe GrowthForecast::Client do
|
|
162
160
|
|
163
161
|
context "#last_response" do
|
164
162
|
include_context "stub_list_graph" if ENV['MOCK'] == 'on'
|
163
|
+
before { @client.list_graph }
|
165
164
|
subject { @client.last_response }
|
166
165
|
it { should be_kind_of HTTP::Message }
|
167
166
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,9 @@ require "bundler/setup"
|
|
4
4
|
ENV['MOCK'] ||= 'on'
|
5
5
|
require "pry"
|
6
6
|
require 'growthforecast-client'
|
7
|
-
require 'webmock/rspec'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'cgi'
|
9
|
+
WebMock.allow_net_connect! if ENV['MOCK'] == 'off'
|
8
10
|
|
9
11
|
ROOT = File.dirname(__FILE__)
|
10
12
|
Dir[File.expand_path("support/**/*.rb", ROOT)].each {|f| require f }
|
@@ -13,3 +15,20 @@ RSpec.configure do |config|
|
|
13
15
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
14
16
|
config.run_all_when_everything_filtered = true
|
15
17
|
end
|
18
|
+
|
19
|
+
def u(str)
|
20
|
+
::CGI.unescape(str.gsub('%20', '+')) if str
|
21
|
+
end
|
22
|
+
|
23
|
+
def e(str)
|
24
|
+
::CGI.escape(str).gsub('+', '%20') if str
|
25
|
+
end
|
26
|
+
|
27
|
+
def base_uri
|
28
|
+
'http://localhost:5125'
|
29
|
+
end
|
30
|
+
|
31
|
+
def client
|
32
|
+
GrowthForecast::Client.new(base_uri)
|
33
|
+
end
|
34
|
+
|
data/spec/support/mock.rb
CHANGED
@@ -1,31 +1,27 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
base_uri = 'http://localhost:5125'
|
4
|
-
|
5
3
|
shared_context "stub_list_graph" do
|
6
|
-
|
4
|
+
def list_graph_example
|
7
5
|
[
|
8
6
|
{"service_name"=>"app name",
|
9
7
|
"section_name"=>"host name",
|
10
8
|
"graph_name"=>"<1sec count",
|
11
9
|
"id"=>1},
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
{"service_name"=>"app name",
|
11
|
+
"section_name"=>"host name",
|
12
|
+
"graph_name"=>"<2sec count",
|
13
|
+
"id"=>2},
|
16
14
|
]
|
17
|
-
|
15
|
+
end
|
18
16
|
|
19
17
|
proc = Proc.new do
|
20
|
-
# WebMock.allow_net_connect!
|
21
18
|
stub_request(:get, "#{base_uri}/json/list/graph").to_return(:status => 200, :body => list_graph_example.to_json)
|
22
19
|
end
|
23
20
|
before(:each, &proc)
|
24
|
-
before(:all, &proc)
|
25
21
|
end
|
26
22
|
|
27
23
|
shared_context "stub_get_graph" do
|
28
|
-
|
24
|
+
def graph_example
|
29
25
|
{
|
30
26
|
"number"=>0,
|
31
27
|
"llimit"=>-1000000000,
|
@@ -51,19 +47,18 @@ shared_context "stub_get_graph" do
|
|
51
47
|
"sllimit"=>-100000,
|
52
48
|
"md5"=>"3c59dc048e8850243be8079a5c74d079"
|
53
49
|
}
|
54
|
-
|
50
|
+
end
|
55
51
|
|
56
52
|
proc = Proc.new do
|
57
|
-
stub_request(:get, "#{base_uri}/api/#{graph['service_name']}/#{graph['section_name']}/#{graph['graph_name']}").
|
53
|
+
stub_request(:get, "#{base_uri}/api/#{e graph['service_name']}/#{e graph['section_name']}/#{e graph['graph_name']}").
|
58
54
|
to_return(:status => 200, :body => graph_example.to_json)
|
59
55
|
end
|
60
56
|
before(:each, &proc)
|
61
|
-
before(:all, &proc)
|
62
57
|
end
|
63
58
|
|
64
59
|
shared_context "stub_get_graph_by_id" do
|
65
60
|
# /json/graph/:id does not return `meta` and `md5`
|
66
|
-
|
61
|
+
def graph_example
|
67
62
|
{
|
68
63
|
"number"=>0,
|
69
64
|
"llimit"=>-1000000000,
|
@@ -89,33 +84,37 @@ shared_context "stub_get_graph_by_id" do
|
|
89
84
|
"sllimit"=>-100000,
|
90
85
|
# "md5"=>"3c59dc048e8850243be8079a5c74d079"
|
91
86
|
}
|
92
|
-
|
87
|
+
end
|
93
88
|
|
94
89
|
proc = Proc.new do
|
95
90
|
stub_request(:get, "#{base_uri}/json/graph/#{graph['id']}").
|
96
91
|
to_return(:status => 200, :body => graph_example.to_json)
|
97
92
|
end
|
98
93
|
before(:each, &proc)
|
99
|
-
before(:all, &proc)
|
100
94
|
end
|
101
95
|
|
102
96
|
shared_context "stub_post_graph" do
|
103
97
|
include_context "stub_get_graph"
|
104
|
-
|
105
|
-
stub_request(:post, "#{base_uri}/api/#{graph['service_name']}/#{graph['section_name']}/#{graph['graph_name']}").
|
98
|
+
before do
|
99
|
+
stub_request(:post, "#{base_uri}/api/#{e graph['service_name']}/#{e graph['section_name']}/#{e graph['graph_name']}").
|
106
100
|
to_return(:status => 200, :body => { "error" => 0, "data" => graph_example }.to_json)
|
107
101
|
end
|
108
|
-
before(:each, &proc)
|
109
|
-
before(:all, &proc)
|
110
102
|
end
|
111
103
|
|
112
104
|
shared_context "stub_delete_graph" do
|
113
105
|
proc = Proc.new do
|
114
|
-
stub_request(:post, "#{base_uri}/delete/#{graph['service_name']}/#{graph['section_name']}/#{graph['graph_name']}").
|
106
|
+
stub_request(:post, "#{base_uri}/delete/#{e graph['service_name']}/#{e graph['section_name']}/#{e graph['graph_name']}").
|
107
|
+
to_return(:status => 200, :body => { "error" => 0 }.to_json)
|
108
|
+
end
|
109
|
+
before(:each, &proc)
|
110
|
+
end
|
111
|
+
|
112
|
+
shared_context "stub_delete_graph_by_id" do
|
113
|
+
proc = Proc.new do
|
114
|
+
stub_request(:post, "#{base_uri}/json/delete/graph/#{id}").
|
115
115
|
to_return(:status => 200, :body => { "error" => 0 }.to_json)
|
116
116
|
end
|
117
117
|
before(:each, &proc)
|
118
|
-
before(:all, &proc)
|
119
118
|
end
|
120
119
|
|
121
120
|
shared_context "stub_edit_graph" do
|
@@ -126,37 +125,89 @@ shared_context "stub_edit_graph" do
|
|
126
125
|
to_return(:status => 200, :body => { "error" => 0 }.to_json)
|
127
126
|
end
|
128
127
|
before(:each, &proc)
|
129
|
-
before(:all, &proc)
|
130
128
|
end
|
131
129
|
|
132
130
|
shared_context "stub_list_complex" do
|
133
|
-
|
131
|
+
def list_complex_example
|
134
132
|
[
|
135
133
|
{"service_name"=>"app name",
|
136
134
|
"section_name"=>"host name",
|
137
135
|
"graph_name"=>"complex graph test",
|
138
136
|
"id"=>1},
|
139
137
|
]
|
140
|
-
|
141
|
-
let(:complex_example) {
|
142
|
-
list_complex_example.first
|
143
|
-
}
|
138
|
+
end
|
144
139
|
|
145
140
|
proc = Proc.new do
|
146
141
|
stub_request(:get, "#{base_uri}/json/list/complex").
|
147
142
|
to_return(:status => 200, :body => list_complex_example.to_json)
|
148
143
|
end
|
149
144
|
before(:each, &proc)
|
150
|
-
|
145
|
+
end
|
146
|
+
|
147
|
+
shared_context "stub_get_complex" do
|
148
|
+
def complex_example
|
149
|
+
{"number"=>0,
|
150
|
+
"complex"=>true,
|
151
|
+
"created_at"=>"2013/05/20 15:08:28",
|
152
|
+
"service_name"=>"app name",
|
153
|
+
"section_name"=>"host name",
|
154
|
+
"id"=>1,
|
155
|
+
"graph_name"=>"complex graph test",
|
156
|
+
"data"=>
|
157
|
+
[{"gmode"=>"gauge", "stack"=>false, "type"=>"AREA", "graph_id"=>218},
|
158
|
+
{"gmode"=>"gauge", "stack"=>true, "type"=>"AREA", "graph_id"=>217}],
|
159
|
+
"sumup"=>false,
|
160
|
+
"description"=>"complex graph test",
|
161
|
+
"sort"=>10,
|
162
|
+
"updated_at"=>"2013/05/20 15:08:28"}
|
163
|
+
end
|
164
|
+
|
165
|
+
proc = Proc.new do
|
166
|
+
stub_request(:get, "#{base_uri}/json/complex/#{e to_complex['service_name']}/#{e to_complex['section_name']}/#{e to_complex['graph_name']}").
|
167
|
+
to_return(:status => 200, :body => complex_example.to_json)
|
168
|
+
end
|
169
|
+
before(:each, &proc)
|
170
|
+
end
|
171
|
+
|
172
|
+
shared_context "stub_get_complex_by_id" do
|
173
|
+
def complex_example
|
174
|
+
{"number"=>0,
|
175
|
+
"complex"=>true,
|
176
|
+
"created_at"=>"2013/05/20 15:08:28",
|
177
|
+
"service_name"=>"app name",
|
178
|
+
"section_name"=>"host name",
|
179
|
+
"id"=>1,
|
180
|
+
"graph_name"=>"complex graph test",
|
181
|
+
"data"=>
|
182
|
+
[{"gmode"=>"gauge", "stack"=>false, "type"=>"AREA", "graph_id"=>218},
|
183
|
+
{"gmode"=>"gauge", "stack"=>true, "type"=>"AREA", "graph_id"=>217}],
|
184
|
+
"sumup"=>false,
|
185
|
+
"description"=>"complex graph test",
|
186
|
+
"sort"=>10,
|
187
|
+
"updated_at"=>"2013/05/20 15:08:28"}
|
188
|
+
end
|
189
|
+
|
190
|
+
proc = Proc.new do
|
191
|
+
stub_request(:get, "#{base_uri}/json/complex/#{id}").
|
192
|
+
to_return(:status => 200, :body => complex_example.to_json)
|
193
|
+
end
|
194
|
+
before(:each, &proc)
|
151
195
|
end
|
152
196
|
|
153
197
|
shared_context "stub_delete_complex" do
|
154
198
|
proc = Proc.new do
|
155
|
-
stub_request(:post, "#{base_uri}/
|
199
|
+
stub_request(:post, "#{base_uri}/json/delete/complex/#{e to_complex['service_name']}/#{e to_complex['section_name']}/#{e to_complex['graph_name']}").
|
200
|
+
to_return(:status => 200, :body => { "error" => 0 }.to_json)
|
201
|
+
end
|
202
|
+
before(:each, &proc)
|
203
|
+
end
|
204
|
+
|
205
|
+
shared_context "stub_delete_complex_by_id" do
|
206
|
+
proc = Proc.new do
|
207
|
+
stub_request(:post, "#{base_uri}/delete_complex/#{id}").
|
156
208
|
to_return(:status => 200, :body => { "error" => 0 }.to_json)
|
157
209
|
end
|
158
210
|
before(:each, &proc)
|
159
|
-
before(:all, &proc)
|
160
211
|
end
|
161
212
|
|
162
213
|
shared_context "stub_create_complex" do
|
@@ -164,7 +215,7 @@ shared_context "stub_create_complex" do
|
|
164
215
|
|
165
216
|
proc = Proc.new do
|
166
217
|
list_graph_example.each do |graph|
|
167
|
-
stub_request(:get, "#{base_uri}/api/#{graph['service_name']}/#{graph['section_name']}/#{graph['graph_name']}").
|
218
|
+
stub_request(:get, "#{base_uri}/api/#{e graph['service_name']}/#{e graph['section_name']}/#{e graph['graph_name']}").
|
168
219
|
to_return(:status => 200, :body => graph.to_json)
|
169
220
|
end
|
170
221
|
|
@@ -172,6 +223,5 @@ shared_context "stub_create_complex" do
|
|
172
223
|
to_return(:status => 200, :body => { "error" => 0 }.to_json)
|
173
224
|
end
|
174
225
|
before(:each, &proc)
|
175
|
-
before(:all, &proc)
|
176
226
|
end
|
177
227
|
|
data/spec/support/setup.rb
CHANGED
@@ -1,22 +1,49 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
shared_context "setup_growthforecast_client" do
|
4
|
-
before(:all) { @client = GrowthForecast::Client.new('http://localhost:5125') }
|
5
|
-
|
6
4
|
include_context "stub_list_graph" if ENV['MOCK'] == 'on'
|
7
|
-
let(:graphs) {
|
5
|
+
let(:graphs) { client.list_graph }
|
8
6
|
let(:graph) { graphs.first }
|
7
|
+
let(:from_graphs) do
|
8
|
+
[
|
9
|
+
{
|
10
|
+
"service_name" => graphs[0]["service_name"],
|
11
|
+
"section_name" => graphs[0]["section_name"],
|
12
|
+
"graph_name" => graphs[0]["graph_name"],
|
13
|
+
"gmode" => "gauge",
|
14
|
+
"stack" => false,
|
15
|
+
"type" => "AREA",
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"service_name" => graphs[1]["service_name"],
|
19
|
+
"section_name" => graphs[1]["section_name"],
|
20
|
+
"graph_name" => graphs[1]["graph_name"],
|
21
|
+
"gmode" => "gauge",
|
22
|
+
"stack" => false,
|
23
|
+
"type" => "AREA"
|
24
|
+
},
|
25
|
+
]
|
26
|
+
end
|
27
|
+
let(:to_complex) do
|
28
|
+
{
|
29
|
+
"service_name" => graphs.first["service_name"],
|
30
|
+
"section_name" => graphs.first["section_name"],
|
31
|
+
"graph_name" => "complex graph test",
|
32
|
+
"description" => "complex graph test",
|
33
|
+
"sort" => 10
|
34
|
+
}
|
35
|
+
end
|
9
36
|
|
10
37
|
include_context "stub_post_graph" if ENV['MOCK'] == 'on'
|
11
38
|
include_context "stub_delete_graph" if ENV['MOCK'] == 'on'
|
12
|
-
before
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
39
|
+
before {
|
40
|
+
client.delete_graph("app name", "host name", "<1sec count") rescue nil
|
41
|
+
client.delete_graph("app name", "host name", "<2sec count") rescue nil
|
42
|
+
client.post_graph("app name", "host name", "<1sec count", { 'number' => 0 }) rescue nil
|
43
|
+
client.post_graph("app name", "host name", "<2sec count", { 'number' => 0 }) rescue nil
|
17
44
|
}
|
18
|
-
after
|
19
|
-
|
20
|
-
|
45
|
+
after {
|
46
|
+
client.delete_graph("app name", "host name", "<1sec count") rescue nil
|
47
|
+
client.delete_graph("app name", "host name", "<2sec count") rescue nil
|
21
48
|
}
|
22
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: growthforecast-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.62.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.0.
|
160
|
+
rubygems_version: 2.0.2
|
161
161
|
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: A Ruby Client Library for GrowthForecast API
|