bluebox-boxcutter 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,91 @@
1
+ require 'bluebox-boxcutter'
2
+ require 'bluebox-boxcutter/cli'
3
+
4
+ # stop commander from automatically running.
5
+ at_exit {
6
+ module Commander
7
+ class Runner
8
+ def run!()
9
+ ;
10
+ end
11
+ end
12
+ end
13
+ }
14
+
15
+ # don't put color escape codes in output, ever.
16
+ Boxcutter.no_colors!
17
+ Boxcutter.quiet!
18
+
19
+ # fake cookies so tests can work with no browser present.
20
+ module Spunkmeyer
21
+ def self.cookies
22
+ [ 'foo', {value: 'bar'} ]
23
+ end
24
+ end
25
+
26
+ # prevent any actual http requests from happening
27
+ module Boxcutter
28
+ class Boxpanel
29
+ def self.get_html(path, options); raise "unexpected get call" end
30
+ def self.get(path, options); raise "unexpected get call" end
31
+ def self.post(path, options); raise "unexpected post call" end
32
+ end
33
+ end
34
+
35
+ # prevent any actual http requests from happening
36
+ module Boxcutter
37
+ module Razor
38
+ class StubbleClient
39
+ def self.get(path, options); raise "unexpected get call" end
40
+ def self.post(path, options); raise "unexpected post call" end
41
+ def self.delete(path, options); raise "unexpected delete call" end
42
+ end
43
+ end
44
+ end
45
+
46
+ FIXTURES = "#{File.dirname __FILE__}/fixtures"
47
+
48
+ def stub_boxpanel_calls!
49
+ {
50
+ '/private/hosts.json' => '/private/hosts.json',
51
+ '/private/hosts/show/123.json' => '/private/hosts/show/123.json',
52
+ '/private/service_password' => '/private/service_password',
53
+ '/private/service_password/fetch_password/163' => '/private/service_passwords/fetch_password/163',
54
+ '/private/service_password/fetch_password/164' => '/private/service_passwords/fetch_password/164',
55
+ '/private/service_password/fetch_password/165' => '/private/service_passwords/fetch_password/165'
56
+ }.each_pair do |path, fixture_path|
57
+ stub_path! path, fixture_path
58
+ end
59
+ fake_machine_search!
60
+ end
61
+
62
+ def fake_machine_search!
63
+ Boxcutter::Boxpanel.stub(:post) do |path, opts|
64
+ raise "#{path} not stubbed" unless path == '/private/hosts/live_search_machines'
65
+ search = Regexp.new opts[:body][:search]
66
+ File.read("#{FIXTURES}/private/hosts/live_search_machines").split("\n").
67
+ select { |l| l =~ search }.join("\n")
68
+ end
69
+ end
70
+
71
+ def stub_path!(path, fixture_path)
72
+ if path.include?('json')
73
+ Boxcutter::Boxpanel.stub(:get).with(path).and_return File.read("#{FIXTURES}/#{fixture_path}")
74
+ else
75
+ Boxcutter::Boxpanel.stub(:get_html).with(path).and_return Nokogiri::HTML File.read("#{FIXTURES}/#{fixture_path}")
76
+ end
77
+ end
78
+
79
+ def capture_stdout
80
+ out = StringIO.new
81
+ $stdout = out
82
+ yield
83
+ out.string
84
+ ensure
85
+ $stdout = STDOUT
86
+ end
87
+
88
+ # invoke commander as if from the shell, inside this process.
89
+ def boxcutter_stdout(cmd, *args)
90
+ capture_stdout { command(cmd.to_sym).run *args }
91
+ end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Boxcutter do
4
+
5
+ before do
6
+ stub_boxpanel_calls!
7
+ end
8
+
9
+ it 'should search machines' do
10
+ actual = boxcutter_stdout 'machine-search', 'foo[1-2]'
11
+ expected = <<-eos
12
+ +------+-----+--------------------------------------------------------+
13
+ | name | id | url |
14
+ +------+-----+--------------------------------------------------------+
15
+ | foo1 | 123 | https://boxpanel.bluebox.net/private/machines/123/edit |
16
+ | foo2 | 124 | https://boxpanel.bluebox.net/private/machines/124/edit |
17
+ +------+-----+--------------------------------------------------------+
18
+ eos
19
+ actual.should == expected
20
+ end
21
+
22
+
23
+ it 'should show a machine' do
24
+ actual = boxcutter_stdout 'machine-show', 'foo1'
25
+ expected = <<-eos
26
+ +-------------------------------------+----------------+
27
+ | key | value |
28
+ +-------------------------------------+----------------+
29
+ | id | 98765 |
30
+ | network_interfaces_eth0_mac_address | 11:11:11:11:11 |
31
+ | network_interfaces_eth0_id | 68686 |
32
+ | hostname | foo1.blah.com |
33
+ | asset_serial | FFFFFF |
34
+ +-------------------------------------+----------------+
35
+ eos
36
+ actual.should == expected
37
+ end
38
+
39
+ it 'should search passwords' do
40
+ actual = boxcutter_stdout 'password', 'foo number \d'
41
+ expected = <<eos
42
+ +--------------+--------------------------+--------------+------+
43
+ | name | uri | user | pass |
44
+ +--------------+--------------------------+--------------+------+
45
+ | foo number 1 | https://some-auth-url | some user | XXXX |
46
+ | foo number 2 | https://another-auth-url | another user | YYYY |
47
+ +--------------+--------------------------+--------------+------+
48
+ eos
49
+ actual.should == expected
50
+ end
51
+
52
+ it 'should show razor tags' do
53
+ Boxcutter::Razor::StubbleClient.stub(:tags).and_return [ 'sl-6', 'ubuntu' ]
54
+ actual = boxcutter_stdout 'razor-tags'
55
+ expected = <<eos
56
+ +--------+
57
+ | name |
58
+ +--------+
59
+ | sl-6 |
60
+ | ubuntu |
61
+ +--------+
62
+ eos
63
+ actual.should == expected
64
+ end
65
+
66
+ it 'shold show razor logs' do
67
+ Boxcutter::Razor::StubbleClient.stub(:log).and_return [
68
+ {'state' => 'init', 'node_uuid' => 'xxx', 'timestamp' => 1374309911, 'result' => 'n/a' },
69
+ {'state' => 'postinstall', 'node_uuid' => 'xxx', 'timestamp' => 1374309986, 'result' => 'done'}
70
+ ]
71
+ actual = boxcutter_stdout 'razor-log', 'foo1'
72
+ expected = <<eos
73
+ +-------------+---------------------------+--------+
74
+ | state | timestamp | result |
75
+ +-------------+---------------------------+--------+
76
+ | init | 2013-07-20T08:45:11+00:00 | n/a |
77
+ | postinstall | 2013-07-20T08:46:26+00:00 | done |
78
+ +-------------+---------------------------+--------+
79
+ eos
80
+ actual.should == expected
81
+ end
82
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bluebox-boxcutter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.14
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Cooper
9
+ - Tim Miller
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-01-10 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: colorize
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: commander
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: httparty
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: mash
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: nokogiri
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :runtime
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: spunkmeyer
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: 0.0.5
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.0.5
111
+ - !ruby/object:Gem::Dependency
112
+ name: terminal-table
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: rake
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: rspec
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ description: cli for boxpanel.
160
+ email:
161
+ - ''
162
+ executables:
163
+ - boxcutter
164
+ extensions: []
165
+ extra_rdoc_files: []
166
+ files:
167
+ - .gitignore
168
+ - CHANGELOG.md
169
+ - Gemfile
170
+ - Gemfile.lock
171
+ - README.md
172
+ - Rakefile
173
+ - bin/boxcutter
174
+ - bluebox-boxcutter.gemspec
175
+ - doc/screenshot.png
176
+ - lib/bluebox-boxcutter.rb
177
+ - lib/bluebox-boxcutter/cli.rb
178
+ - lib/bluebox-boxcutter/git.rb
179
+ - lib/bluebox-boxcutter/kvm.rb
180
+ - lib/bluebox-boxcutter/machine.rb
181
+ - lib/bluebox-boxcutter/password.rb
182
+ - lib/bluebox-boxcutter/razor.rb
183
+ - lib/bluebox-boxcutter/ui.rb
184
+ - lib/bluebox-boxcutter/version.rb
185
+ - spec/boxcutter_spec.rb
186
+ - spec/fixtures/private/hosts.json
187
+ - spec/fixtures/private/hosts/live_search_machines
188
+ - spec/fixtures/private/hosts/show/123.json
189
+ - spec/fixtures/private/machines/123/edit
190
+ - spec/fixtures/private/service_password
191
+ - spec/fixtures/private/service_passwords/fetch_password/163
192
+ - spec/fixtures/private/service_passwords/fetch_password/164
193
+ - spec/fixtures/private/service_passwords/fetch_password/165
194
+ - spec/git_spec.rb
195
+ - spec/machine_spec.rb
196
+ - spec/razor_spec.rb
197
+ - spec/spec_helper.rb
198
+ - spec/ui_spec.rb
199
+ homepage: https://github.blueboxgrid.com/bluebox-tech/boxcutter
200
+ licenses: []
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ! '>='
209
+ - !ruby/object:Gem::Version
210
+ version: 1.9.1
211
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: 1.3.7
217
+ requirements: []
218
+ rubyforge_project:
219
+ rubygems_version: 1.8.23
220
+ signing_key:
221
+ specification_version: 3
222
+ summary: cli for boxpanel
223
+ test_files: []