pvdgm-bs-client 0.1.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 +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +75 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/bin/beanstalk_api +8 -0
- data/lib/pvdgm-bs-client.rb +15 -0
- data/lib/pvdgm-bs-client/base_resource.rb +103 -0
- data/lib/pvdgm-bs-client/beanstalk_api_options.rb +136 -0
- data/lib/pvdgm-bs-client/prompters/job_prompter.rb +32 -0
- data/lib/pvdgm-bs-client/prompters/to_tube_prompter.rb +25 -0
- data/lib/pvdgm-bs-client/prompters/tube_prompter.rb +25 -0
- data/lib/pvdgm-bs-client/resources/job.rb +61 -0
- data/lib/pvdgm-bs-client/resources/statistics.rb +29 -0
- data/lib/pvdgm-bs-client/resources/tube.rb +124 -0
- data/spec/base_resource_spec.rb +208 -0
- data/spec/beanstalk_api_options_spec.rb +206 -0
- data/spec/spec_helper.rb +21 -0
- metadata +179 -0
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BeanstalkApiOptions do
|
4
|
+
|
5
|
+
# The current set of all resources. This automatically updates if new
|
6
|
+
# resources are added to the application
|
7
|
+
RESOURCES = Resources.constants.map { | const | ActiveSupport::Inflector.underscore(const.to_s) }
|
8
|
+
COMMANDS = RESOURCES.inject(Hash.new { | h, k | h[k] = [] }) do | acc, resource |
|
9
|
+
acc.tap do | a |
|
10
|
+
a[resource] = eval("Resources::#{ActiveSupport::Inflector.camelize(resource)}").instance_methods(false)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@cut = BeanstalkApiOptions.new
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'Public Methods' do
|
19
|
+
|
20
|
+
context '#parse_options!' do
|
21
|
+
|
22
|
+
context 'without an api token' do
|
23
|
+
|
24
|
+
it "should raise an exception if no API token has been specified" do
|
25
|
+
argv = []
|
26
|
+
expect { @cut.parse_options!(argv) }.
|
27
|
+
to raise_error(SystemExit)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with an api token' do
|
33
|
+
|
34
|
+
it "should provide a default resource and command if none is specified on the command line" do
|
35
|
+
argv = ['--token', 'the_token' ]
|
36
|
+
expect(@cut.parse_options!(argv)).
|
37
|
+
to eq([ { all_stats: false, server: 'www.abaqis.com', use_ssl: true, api_token: 'the_token' }, # Default options
|
38
|
+
'statistics', # Default resource
|
39
|
+
'list' ]) # Default command
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should use the specified resource and infer the command when the command is not specified" do
|
43
|
+
argv = ['--token', 'the_token', 'tube' ]
|
44
|
+
expect(@cut.parse_options!(argv)).
|
45
|
+
to eq([ { all_stats: false, server: 'www.abaqis.com', use_ssl: true, api_token: 'the_token' }, # Default options
|
46
|
+
'tube', # Specified resource
|
47
|
+
'list' ]) # Default command
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should use the specified resource and command when specified" do
|
51
|
+
argv = ['--token', 'the_token', 'tube', 'show' ]
|
52
|
+
expect(@cut.parse_options!(argv)).
|
53
|
+
to eq([ { all_stats: false, server: 'www.abaqis.com', use_ssl: true, api_token: 'the_token' }, # Default options
|
54
|
+
'tube', # Specified resource
|
55
|
+
'show' ]) # Specified command
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should render the help display and exit when the help option is specified" do
|
59
|
+
argv = [ '--help' ]
|
60
|
+
expect { @cut.parse_options!(argv) }.
|
61
|
+
to raise_error(SystemExit)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should set the server option" do
|
65
|
+
argv = ['--token', 'the_token', '--server', 'test.abaqis.int' ]
|
66
|
+
expect(@cut.parse_options!(argv)).
|
67
|
+
to eq([ { all_stats: false,
|
68
|
+
server: 'test.abaqis.int',
|
69
|
+
use_ssl: true,
|
70
|
+
api_token: 'the_token' }, # Default options
|
71
|
+
'statistics', # Default resource
|
72
|
+
'list' ]) # Default command
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should set the server/ssl option for local testing" do
|
76
|
+
argv = ['--token', 'the_token', '--local']
|
77
|
+
expect(@cut.parse_options!(argv)).
|
78
|
+
to eq([ { all_stats: false,
|
79
|
+
server: 'localhost:3000',
|
80
|
+
use_ssl: false,
|
81
|
+
api_token: 'the_token' }, # Default options
|
82
|
+
'statistics', # Default resource
|
83
|
+
'list' ]) # Default command
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should set the server/ssl option for uat testing" do
|
87
|
+
argv = ['--token', 'the_token', '--uat']
|
88
|
+
expect(@cut.parse_options!(argv)).
|
89
|
+
to eq([ { all_stats: false,
|
90
|
+
server: 'uat.abaqis.com',
|
91
|
+
use_ssl: true,
|
92
|
+
api_token: 'the_token' }, # Default options
|
93
|
+
'statistics', # Default resource
|
94
|
+
'list' ]) # Default command
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should display the resources/commands and exit" do
|
98
|
+
argv = [ '--list' ]
|
99
|
+
expect { @cut.parse_options!(argv) }.
|
100
|
+
to raise_error(SystemExit)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should set the tube name option" do
|
104
|
+
argv = ['--token', 'the_token', '--tube', 'big_tube']
|
105
|
+
expect(@cut.parse_options!(argv)).
|
106
|
+
to eq([ { all_stats: false,
|
107
|
+
server: 'www.abaqis.com',
|
108
|
+
use_ssl: true,
|
109
|
+
tube: 'big_tube',
|
110
|
+
api_token: 'the_token' }, # Default options
|
111
|
+
'statistics', # Default resource
|
112
|
+
'list' ]) # Default command
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should set the all statistics flag" do
|
116
|
+
argv = ['--token', 'the_token', '--all']
|
117
|
+
expect(@cut.parse_options!(argv)).
|
118
|
+
to eq([ { all_stats: true,
|
119
|
+
server: 'www.abaqis.com',
|
120
|
+
use_ssl: true,
|
121
|
+
api_token: 'the_token' }, # Default options
|
122
|
+
'statistics', # Default resource
|
123
|
+
'list' ]) # Default command
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
context '#invoke_command' do
|
131
|
+
|
132
|
+
it "should construct the resource with the options and invoke the command on the resource" do
|
133
|
+
@cut.should_receive(:parse_options!).
|
134
|
+
and_return( [ { }, 'tube', 'list' ] )
|
135
|
+
|
136
|
+
mock_tube = double("Tube")
|
137
|
+
mock_tube.should_receive(:send).
|
138
|
+
with(:list)
|
139
|
+
|
140
|
+
Resources::Tube.should_receive(:new).
|
141
|
+
with({}).
|
142
|
+
and_return(mock_tube)
|
143
|
+
|
144
|
+
@cut.invoke_command
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'Private Methods' do
|
151
|
+
|
152
|
+
context '#valid_command?' do
|
153
|
+
|
154
|
+
it "should return true if the specified resource has the specified command" do
|
155
|
+
COMMANDS.each_pair do | resource, commands |
|
156
|
+
commands.each do | command |
|
157
|
+
expect(@cut.send(:valid_command?, resource, command.to_s)).
|
158
|
+
to be_true, "'#{command}' should be a valid command for resource '#{resource}'"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should return false if the specified resource doesn't have the specified command" do
|
164
|
+
expect(@cut.send(:valid_command?, 'tube', 'invalid_command')).
|
165
|
+
to be_false
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should return false if the specified resource is nil" do
|
169
|
+
expect(@cut.send(:valid_command?, nil, 'list')).
|
170
|
+
to be_false
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should return false if the specified command is nil" do
|
174
|
+
expect(@cut.send(:valid_command?, 'tube', nil)).
|
175
|
+
to be_false
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should do something horrible if the resource name is bogus" do
|
179
|
+
expect { @cut.send(:valid_command?, 'bottle', 'list') }.
|
180
|
+
to raise_error(NameError)
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
context '#valid_resource' do
|
186
|
+
|
187
|
+
it "should return true if the specified resource is valid" do
|
188
|
+
expect(@cut.send(:valid_resource?, 'tube')).
|
189
|
+
to be_true
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should return false if the specified resource is not valid" do
|
193
|
+
expect(@cut.send(:valid_resource?, 'tuber')).
|
194
|
+
to be_false
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should return false if the specified resource is nil" do
|
198
|
+
expect(@cut.send(:valid_resource?, nil)).
|
199
|
+
to be_false
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
# Here's the deal. We need to make sure that the API_TOKEN is not set
|
5
|
+
# environment before the tests are run. In fact, the ENV['API_TOKEN']
|
6
|
+
# must be cleared before the ServiceMgrOptions class is loaded. That's
|
7
|
+
# why we do it before the requires.
|
8
|
+
#
|
9
|
+
# I'm just sayin'
|
10
|
+
#
|
11
|
+
ENV.delete('API_TOKEN')
|
12
|
+
require 'rspec'
|
13
|
+
require 'pvdgm-bs-client'
|
14
|
+
|
15
|
+
# Requires supporting files with custom matchers and macros, etc,
|
16
|
+
# in ./support/ and its subdirectories.
|
17
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pvdgm-bs-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Sieh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.14
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.14
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: terminal-table
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: highline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: rspec
|
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: rdoc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.12'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.12'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: jeweler
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.8.7
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.8.7
|
125
|
+
description: This gem provides command-line tools to use the beanstalk api.
|
126
|
+
email: dave.sieh@providigm.com
|
127
|
+
executables:
|
128
|
+
- beanstalk_api
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.rdoc
|
133
|
+
files:
|
134
|
+
- ".document"
|
135
|
+
- ".rspec"
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.rdoc
|
140
|
+
- Rakefile
|
141
|
+
- VERSION
|
142
|
+
- bin/beanstalk_api
|
143
|
+
- lib/pvdgm-bs-client.rb
|
144
|
+
- lib/pvdgm-bs-client/base_resource.rb
|
145
|
+
- lib/pvdgm-bs-client/beanstalk_api_options.rb
|
146
|
+
- lib/pvdgm-bs-client/prompters/job_prompter.rb
|
147
|
+
- lib/pvdgm-bs-client/prompters/to_tube_prompter.rb
|
148
|
+
- lib/pvdgm-bs-client/prompters/tube_prompter.rb
|
149
|
+
- lib/pvdgm-bs-client/resources/job.rb
|
150
|
+
- lib/pvdgm-bs-client/resources/statistics.rb
|
151
|
+
- lib/pvdgm-bs-client/resources/tube.rb
|
152
|
+
- spec/base_resource_spec.rb
|
153
|
+
- spec/beanstalk_api_options_spec.rb
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
homepage: http://github.com/j0hnds/pvdgm-bs-client
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.2.2
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: Command-line client tools to use the beanstalk api.
|
179
|
+
test_files: []
|