tugboat 2.2.2 → 2.2.3
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/.rubocop.yml +520 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +0 -6
- data/README.md +34 -2
- data/Rakefile +6 -1
- data/bin/tugboat +2 -2
- data/features/cassettes/config/Array_of_SSH_Keys_in_Config.yml +1 -1
- data/features/cassettes/config/Single_SSH_key_as_number_in_config.yml +1 -1
- data/features/step_definitions/steps.rb +1 -1
- data/features/support/env.rb +7 -3
- data/lib/tugboat.rb +2 -2
- data/lib/tugboat/cli.rb +394 -444
- data/lib/tugboat/config.rb +43 -61
- data/lib/tugboat/middleware.rb +33 -33
- data/lib/tugboat/middleware/add_key.rb +12 -13
- data/lib/tugboat/middleware/ask_for_credentials.rb +12 -13
- data/lib/tugboat/middleware/base.rb +25 -20
- data/lib/tugboat/middleware/check_configuration.rb +3 -6
- data/lib/tugboat/middleware/check_credentials.rb +0 -1
- data/lib/tugboat/middleware/check_droplet_active.rb +2 -4
- data/lib/tugboat/middleware/check_droplet_inactive.rb +2 -4
- data/lib/tugboat/middleware/config.rb +3 -5
- data/lib/tugboat/middleware/confirm_action.rb +4 -6
- data/lib/tugboat/middleware/create_droplet.rb +27 -44
- data/lib/tugboat/middleware/custom_logger.rb +52 -54
- data/lib/tugboat/middleware/destroy_droplet.rb +5 -6
- data/lib/tugboat/middleware/destroy_image.rb +5 -6
- data/lib/tugboat/middleware/find_droplet.rb +43 -47
- data/lib/tugboat/middleware/find_image.rb +23 -29
- data/lib/tugboat/middleware/halt_droplet.rb +9 -10
- data/lib/tugboat/middleware/info_droplet.rb +30 -33
- data/lib/tugboat/middleware/info_image.rb +1 -1
- data/lib/tugboat/middleware/inject_client.rb +8 -10
- data/lib/tugboat/middleware/inject_configuration.rb +1 -2
- data/lib/tugboat/middleware/list_droplets.rb +9 -10
- data/lib/tugboat/middleware/list_images.rb +9 -9
- data/lib/tugboat/middleware/list_regions.rb +1 -1
- data/lib/tugboat/middleware/list_sizes.rb +1 -1
- data/lib/tugboat/middleware/list_ssh_keys.rb +1 -3
- data/lib/tugboat/middleware/password_reset.rb +6 -7
- data/lib/tugboat/middleware/rebuild_droplet.rb +7 -7
- data/lib/tugboat/middleware/resize_droplet.rb +6 -7
- data/lib/tugboat/middleware/restart_droplet.rb +4 -11
- data/lib/tugboat/middleware/snapshot_droplet.rb +7 -8
- data/lib/tugboat/middleware/ssh_droplet.rb +30 -31
- data/lib/tugboat/middleware/start_droplet.rb +5 -5
- data/lib/tugboat/middleware/wait_for_state.rb +2 -3
- data/lib/tugboat/version.rb +1 -1
- data/spec/cli/add_key_spec.rb +25 -28
- data/spec/cli/authorize_cli_spec.rb +57 -60
- data/spec/cli/config_cli_spec.rb +8 -11
- data/spec/cli/create_cli_spec.rb +40 -46
- data/spec/cli/debug_cli_spec.rb +29 -29
- data/spec/cli/destroy_cli_spec.rb +58 -60
- data/spec/cli/destroy_image_cli_spec.rb +42 -45
- data/spec/cli/droplets_cli_spec.rb +62 -64
- data/spec/cli/env_variable_spec.rb +14 -15
- data/spec/cli/halt_cli_spec.rb +65 -69
- data/spec/cli/help_cli_spec.rb +8 -8
- data/spec/cli/images_cli_spec.rb +28 -30
- data/spec/cli/info_cli_spec.rb +144 -147
- data/spec/cli/info_image_cli_spec.rb +57 -60
- data/spec/cli/keys_cli_spec.rb +8 -10
- data/spec/cli/password_reset_cli_spec.rb +56 -56
- data/spec/cli/rebuild_cli_spec.rb +194 -198
- data/spec/cli/regions_cli_spec.rb +8 -8
- data/spec/cli/resize_cli_spec.rb +54 -56
- data/spec/cli/restart_cli_spec.rb +53 -57
- data/spec/cli/sizes_cli_spec.rb +7 -8
- data/spec/cli/snapshot_cli_spec.rb +50 -53
- data/spec/cli/ssh_cli_spec.rb +41 -42
- data/spec/cli/start_cli_spec.rb +48 -52
- data/spec/cli/verify_cli_spec.rb +22 -25
- data/spec/cli/version_cli_spec.rb +6 -8
- data/spec/cli/wait_cli_spec.rb +50 -52
- data/spec/config_spec.rb +56 -57
- data/spec/middleware/base_spec.rb +5 -6
- data/spec/middleware/check_configuration_spec.rb +5 -7
- data/spec/middleware/check_credentials_spec.rb +9 -10
- data/spec/middleware/check_droplet_active_spec.rb +5 -7
- data/spec/middleware/check_droplet_inactive_spec.rb +5 -7
- data/spec/middleware/find_droplet_spec.rb +4 -5
- data/spec/middleware/find_image_spec.rb +4 -5
- data/spec/middleware/inject_client_spec.rb +9 -12
- data/spec/middleware/inject_configuration_spec.rb +4 -7
- data/spec/middleware/ssh_droplet_spec.rb +70 -73
- data/spec/shared/environment.rb +18 -20
- data/spec/spec_helper.rb +4 -4
- data/tugboat.gemspec +10 -6
- metadata +88 -17
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tugboat::CLI do
|
4
|
-
include_context
|
4
|
+
include_context 'spec'
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
stub_request(:get,
|
9
|
-
|
10
|
-
|
6
|
+
describe 'info_image' do
|
7
|
+
it 'shows an image with a fuzzy name' do
|
8
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
9
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
10
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
|
11
11
|
|
12
|
-
stub_request(:get,
|
13
|
-
|
14
|
-
|
12
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/12789325?per_page=200').
|
13
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
14
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_coreos_image'))
|
15
15
|
|
16
|
-
|
16
|
+
cli.info_image('745.1.0 (alpha)')
|
17
17
|
|
18
18
|
expect($stdout.string).to eq <<-eos
|
19
19
|
Image fuzzy name provided. Finding image ID...done\e[0m, 12789325 (745.1.0 (alpha))
|
@@ -26,17 +26,17 @@ Regions: nyc1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
|
|
26
26
|
eos
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
stub_request(:get,
|
31
|
-
|
32
|
-
|
29
|
+
it 'shows an image with an id' do
|
30
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
31
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
32
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
|
33
33
|
|
34
|
-
stub_request(:get,
|
35
|
-
|
36
|
-
|
34
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/12438838?per_page=200').
|
35
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
36
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_redmine_image'))
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
cli.options = cli.options.merge(id: 12_438_838)
|
39
|
+
cli.info_image
|
40
40
|
|
41
41
|
expect($stdout.string).to eq <<-eos
|
42
42
|
Image id provided. Finding Image...done\e[0m, 12438838 (Redmine on 14.04)
|
@@ -49,17 +49,17 @@ Regions: nyc1,ams1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
|
|
49
49
|
eos
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
53
|
-
stub_request(:get,
|
54
|
-
|
55
|
-
|
52
|
+
it 'shows an image with a name' do
|
53
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
54
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
55
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
|
56
56
|
|
57
|
-
stub_request(:get,
|
58
|
-
|
59
|
-
|
57
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/12438838?per_page=200').
|
58
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
59
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_redmine_image'))
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
cli.options = cli.options.merge(name: 'Redmine on 14.04')
|
62
|
+
cli.info_image
|
63
63
|
|
64
64
|
expect($stdout.string).to eq <<-eos
|
65
65
|
Image name provided. Finding Image...done\e[0m, 12438838 (Redmine on 14.04)
|
@@ -72,30 +72,30 @@ Regions: nyc1,ams1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
|
|
72
72
|
eos
|
73
73
|
end
|
74
74
|
|
75
|
-
it
|
76
|
-
stub_request(:get,
|
77
|
-
|
78
|
-
|
75
|
+
it 'errors if no image with matching id is found' do
|
76
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
77
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
78
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
|
79
79
|
|
80
|
-
stub_request(:get,
|
81
|
-
|
82
|
-
|
80
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/123?per_page=200').
|
81
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
82
|
+
to_return(status: 404, body: fixture('not_found'), headers: {})
|
83
83
|
|
84
|
-
|
85
|
-
expect {
|
84
|
+
cli.options = cli.options.merge(id: '123')
|
85
|
+
expect { cli.info_image }.to raise_error(SystemExit)
|
86
86
|
|
87
87
|
expect($stdout.string).to eq <<-eos
|
88
88
|
Image id provided. Finding Image...Failed to find Image: The resource you were accessing could not be found.
|
89
89
|
eos
|
90
90
|
end
|
91
91
|
|
92
|
-
it
|
93
|
-
stub_request(:get,
|
94
|
-
|
95
|
-
|
92
|
+
it 'errors if no image with matching name is found' do
|
93
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
94
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
95
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
|
96
96
|
|
97
|
-
|
98
|
-
expect {
|
97
|
+
cli.options = cli.options.merge(name: 'foobarbaz')
|
98
|
+
expect { cli.info_image }.to raise_error(SystemExit)
|
99
99
|
|
100
100
|
expect($stdout.string).to eq <<-eos
|
101
101
|
Image name provided. Finding Image...error
|
@@ -103,12 +103,12 @@ Unable to find an image named 'foobarbaz'.
|
|
103
103
|
eos
|
104
104
|
end
|
105
105
|
|
106
|
-
it
|
107
|
-
stub_request(:get,
|
108
|
-
|
109
|
-
|
106
|
+
it 'errors if no image with matching fuzzy name is found' do
|
107
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
108
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
109
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
|
110
110
|
|
111
|
-
expect {
|
111
|
+
expect { cli.info_image('foobarbaz') }.to raise_error(SystemExit)
|
112
112
|
|
113
113
|
expect($stdout.string).to eq <<-eos
|
114
114
|
Image fuzzy name provided. Finding image ID...error
|
@@ -116,18 +116,18 @@ Unable to find an image named 'foobarbaz'.
|
|
116
116
|
eos
|
117
117
|
end
|
118
118
|
|
119
|
-
it
|
120
|
-
|
121
|
-
|
122
|
-
|
119
|
+
it 'allows choice of multiple images' do
|
120
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
121
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
122
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_images'))
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/9801951?per_page=200').
|
125
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
126
|
+
to_return(status: 200, body: fixture('ubuntu_image_9801951'), headers: {})
|
127
127
|
|
128
|
-
|
128
|
+
$stdin.should_receive(:gets).and_return('0')
|
129
129
|
|
130
|
-
|
130
|
+
cli.info_image('ubun')
|
131
131
|
|
132
132
|
expect($stdout.string).to eq <<-eos
|
133
133
|
Image fuzzy name provided. Finding image ID...Multiple images found.
|
@@ -149,8 +149,5 @@ Min Disk Size: 20GB
|
|
149
149
|
Regions: nyc1,ams1,sfo1,nyc2,ams2,sgp1,lon1,nyc3,ams3,fra1
|
150
150
|
eos
|
151
151
|
end
|
152
|
-
|
153
|
-
|
154
152
|
end
|
155
|
-
|
156
153
|
end
|
data/spec/cli/keys_cli_spec.rb
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tugboat::CLI do
|
4
|
-
include_context
|
4
|
+
include_context 'spec'
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
6
|
+
describe 'keys' do
|
7
|
+
it 'shows a list' do
|
8
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/account/keys?per_page=200').
|
9
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
10
|
+
to_return(status: 200, body: fixture('show_keys'), headers: {})
|
8
11
|
|
9
|
-
|
10
|
-
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
|
11
|
-
to_return(:status => 200, :body => fixture('show_keys'), :headers => {})
|
12
|
-
|
13
|
-
@cli.keys
|
12
|
+
cli.keys
|
14
13
|
|
15
14
|
expect($stdout.string).to eq <<-eos
|
16
15
|
SSH Keys:
|
@@ -18,8 +17,7 @@ Name: My SSH Public Key, (id: 512189), fingerprint: 3b:16:bf:e4:8b:00:8b:b8:59:8
|
|
18
17
|
Name: My Other SSH Public Key, (id: 512110), fingerprint: 3b:16:bf:d4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa
|
19
18
|
eos
|
20
19
|
|
21
|
-
expect(a_request(:get,
|
20
|
+
expect(a_request(:get, 'https://api.digitalocean.com/v2/account/keys?per_page=200')).to have_been_made
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
|
-
|
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tugboat::CLI do
|
4
|
-
include_context
|
4
|
+
include_context 'spec'
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
stub_request(:get,
|
9
|
-
|
10
|
-
|
6
|
+
describe 'passwordreset' do
|
7
|
+
it 'resets the root password given a fuzzy name' do
|
8
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
9
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
10
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
11
11
|
|
12
|
-
stub_request(:get,
|
13
|
-
|
14
|
-
|
12
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
13
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
14
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: { 'Content-Type' => 'application/json' })
|
15
15
|
|
16
|
-
stub_request(:post,
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
17
|
+
with(body: '{"type":"password_reset"}',
|
18
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
19
|
+
to_return(status: 200, body: fixture('password_reset_response'), headers: {})
|
20
20
|
|
21
|
-
|
21
|
+
cli.password_reset('example.com')
|
22
22
|
|
23
23
|
expect($stdout.string).to eq <<-eos
|
24
24
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -27,26 +27,26 @@ Your new root password will be emailed to you
|
|
27
27
|
eos
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
31
|
-
stub_request(:get,
|
32
|
-
|
33
|
-
|
30
|
+
it 'resets the root password given an id' do
|
31
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
32
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
33
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
34
34
|
|
35
|
-
stub_request(:get,
|
36
|
-
with(:
|
37
|
-
to_return(:
|
35
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
36
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
37
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: { 'Content-Type' => 'application/json' })
|
38
38
|
|
39
|
-
stub_request(:get,
|
40
|
-
|
41
|
-
|
39
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?per_page=200').
|
40
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
41
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
42
42
|
|
43
|
-
stub_request(:post,
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
44
|
+
with(body: '{"type":"password_reset"}',
|
45
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
46
|
+
to_return(status: 200, body: fixture('password_reset_response'), headers: {})
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
cli.options = cli.options.merge(id: 6_918_990)
|
49
|
+
cli.password_reset
|
50
50
|
|
51
51
|
expect($stdout.string).to eq <<-eos
|
52
52
|
Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
|
@@ -55,22 +55,22 @@ Your new root password will be emailed to you
|
|
55
55
|
eos
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
59
|
-
stub_request(:get,
|
60
|
-
|
61
|
-
|
58
|
+
it 'resets the root password given a name' do
|
59
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
60
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
61
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
62
62
|
|
63
|
-
stub_request(:get,
|
64
|
-
|
65
|
-
|
63
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
64
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
65
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: { 'Content-Type' => 'application/json' })
|
66
66
|
|
67
|
-
stub_request(:post,
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
68
|
+
with(body: '{"type":"password_reset"}',
|
69
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
70
|
+
to_return(status: 200, body: fixture('password_reset_response'), headers: {})
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
cli.options = cli.options.merge(name: 'example.com')
|
73
|
+
cli.password_reset
|
74
74
|
|
75
75
|
expect($stdout.string).to eq <<-eos
|
76
76
|
Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -79,23 +79,23 @@ Your new root password will be emailed to you
|
|
79
79
|
eos
|
80
80
|
end
|
81
81
|
|
82
|
-
it
|
83
|
-
stub_request(:get,
|
84
|
-
|
85
|
-
|
82
|
+
it 'raises SystemExit when a request fails' do
|
83
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
84
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
85
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
86
86
|
|
87
|
-
stub_request(:get,
|
88
|
-
with(:
|
89
|
-
to_return(:
|
87
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
88
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
89
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: { 'Content-Type' => 'application/json' })
|
90
90
|
|
91
|
-
stub_request(:post,
|
92
|
-
|
93
|
-
|
94
|
-
to_return(:
|
91
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
92
|
+
with(body: '{"type":"password_reset"}',
|
93
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
94
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 500, body: '{"status":"ERROR","message":"Some error"}')
|
95
95
|
|
96
|
-
|
96
|
+
cli.options = cli.options.merge(name: 'example.com')
|
97
97
|
|
98
|
-
|
98
|
+
expect { cli.password_reset('example.com') }.to raise_error(SystemExit)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -1,61 +1,60 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tugboat::CLI do
|
4
|
-
include_context
|
4
|
+
include_context 'spec'
|
5
5
|
|
6
|
-
describe
|
7
|
-
it
|
8
|
-
stub_request(:get,
|
9
|
-
|
10
|
-
|
6
|
+
describe 'rebuild' do
|
7
|
+
it 'rebuilds a droplet with a fuzzy name based on an image with a fuzzy name' do
|
8
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
9
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
10
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
11
11
|
|
12
|
-
stub_request(:get,
|
13
|
-
|
14
|
-
|
12
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
13
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
14
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
15
15
|
|
16
|
-
stub_request(:get,
|
17
|
-
|
18
|
-
|
16
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
17
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
18
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
19
19
|
|
20
|
-
stub_request(:post,
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
21
|
+
with(body: '{"type":"rebuild","image":12790328}',
|
22
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
23
|
+
to_return(status: 200, body: '', headers: {})
|
24
24
|
|
25
|
-
expect($stdin).to receive(:gets).and_return(
|
25
|
+
expect($stdin).to receive(:gets).and_return('y')
|
26
26
|
|
27
|
-
|
27
|
+
cli.rebuild('example.com', 'ubuntu-14-04-x64')
|
28
28
|
|
29
29
|
expect($stdout.string).to eq <<-eos
|
30
30
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
31
31
|
Image fuzzy name provided. Finding image ID...done\e[0m, 12790328 (14.04 x64)
|
32
32
|
Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
|
33
33
|
eos
|
34
|
-
|
35
34
|
end
|
36
35
|
|
37
|
-
it
|
38
|
-
stub_request(:get,
|
39
|
-
|
40
|
-
|
36
|
+
it 'rebuilds a droplet with an id based on an image with a fuzzy name' do
|
37
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
38
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
39
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
41
40
|
|
42
|
-
stub_request(:get,
|
43
|
-
|
44
|
-
|
41
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/12790328?per_page=200').
|
42
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
43
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
45
44
|
|
46
|
-
stub_request(:get,
|
47
|
-
|
48
|
-
|
45
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
46
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
47
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
49
48
|
|
50
|
-
stub_request(:post,
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
50
|
+
with(body: '{"type":"rebuild","image":12790328}',
|
51
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
52
|
+
to_return(status: 200, body: '', headers: {})
|
54
53
|
|
55
|
-
expect($stdin).to receive(:gets).and_return(
|
54
|
+
expect($stdin).to receive(:gets).and_return('y')
|
56
55
|
|
57
|
-
|
58
|
-
|
56
|
+
cli.options = cli.options.merge(id: '12790328')
|
57
|
+
cli.rebuild('example.com', 'ubuntu-14-04-x64')
|
59
58
|
|
60
59
|
expect($stdout.string).to eq <<-eos
|
61
60
|
Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
|
@@ -64,71 +63,70 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
|
|
64
63
|
eos
|
65
64
|
end
|
66
65
|
|
67
|
-
it
|
68
|
-
stub_request(:get,
|
69
|
-
|
70
|
-
|
66
|
+
it 'rebuilds a droplet with a name based on an image with a fuzzy name' do
|
67
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
68
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
69
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
71
70
|
|
72
|
-
stub_request(:get,
|
73
|
-
|
74
|
-
|
71
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
72
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
73
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
75
74
|
|
76
|
-
stub_request(:get,
|
77
|
-
|
78
|
-
|
75
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/12790328?per_page=200').
|
76
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
77
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
79
78
|
|
80
|
-
stub_request(:get,
|
81
|
-
|
82
|
-
|
79
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
80
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
81
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
83
82
|
|
84
|
-
stub_request(:post,
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
84
|
+
with(body: '{"type":"rebuild","image":12790328}',
|
85
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
86
|
+
to_return(status: 200, body: '', headers: {})
|
88
87
|
|
89
|
-
expect($stdin).to receive(:gets).and_return(
|
88
|
+
expect($stdin).to receive(:gets).and_return('y')
|
90
89
|
|
91
|
-
|
92
|
-
|
90
|
+
cli.options = cli.options.merge(name: 'example.com')
|
91
|
+
cli.rebuild('example.com', 'ubuntu-14-04-x64')
|
93
92
|
|
94
93
|
expect($stdout.string).to eq <<-eos
|
95
94
|
Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
96
95
|
Image fuzzy name provided. Finding image ID...done\e[0m, 12790328 (14.04 x64)
|
97
96
|
Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64)...Rebuild complete
|
98
97
|
eos
|
99
|
-
|
100
98
|
end
|
101
99
|
|
102
|
-
it
|
103
|
-
stub_request(:get,
|
104
|
-
|
105
|
-
|
100
|
+
it 'rebuilds a droplet with a fuzzy name based on an image with an id' do
|
101
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
102
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
103
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
106
104
|
|
107
|
-
stub_request(:get,
|
108
|
-
|
109
|
-
|
105
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
106
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
107
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
110
108
|
|
111
|
-
stub_request(:get,
|
112
|
-
|
113
|
-
|
109
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/12790328?per_page=200').
|
110
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
111
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
114
112
|
|
115
|
-
stub_request(:get,
|
116
|
-
|
117
|
-
|
113
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
114
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
115
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
118
116
|
|
119
|
-
stub_request(:get,
|
120
|
-
|
121
|
-
|
117
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/12790328?per_page=200').
|
118
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
119
|
+
to_return(status: 200, body: fixture('show_image'), headers: {})
|
122
120
|
|
123
|
-
stub_request(:post,
|
124
|
-
|
125
|
-
|
126
|
-
|
121
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
122
|
+
with(body: '{"type":"rebuild","image":6376601}',
|
123
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
124
|
+
to_return(status: 200, body: '', headers: {})
|
127
125
|
|
128
|
-
expect($stdin).to receive(:gets).and_return(
|
126
|
+
expect($stdin).to receive(:gets).and_return('y')
|
129
127
|
|
130
|
-
|
131
|
-
|
128
|
+
cli.options = cli.options.merge(image_id: 12_790_328)
|
129
|
+
cli.rebuild('example.com', 'ubuntu-14-04-x64')
|
132
130
|
|
133
131
|
expect($stdout.string).to eq <<-eos
|
134
132
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -137,36 +135,36 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
|
|
137
135
|
eos
|
138
136
|
end
|
139
137
|
|
140
|
-
it
|
141
|
-
stub_request(:get,
|
142
|
-
|
143
|
-
|
138
|
+
it 'rebuilds a droplet with an id based on an image with an id' do
|
139
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
140
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
141
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
144
142
|
|
145
|
-
stub_request(:get,
|
146
|
-
|
147
|
-
|
143
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
144
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
145
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
148
146
|
|
149
|
-
stub_request(:get,
|
150
|
-
|
151
|
-
|
147
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/12790328?per_page=200').
|
148
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
149
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
152
150
|
|
153
|
-
stub_request(:get,
|
154
|
-
|
155
|
-
|
151
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
152
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
153
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
156
154
|
|
157
|
-
stub_request(:get,
|
158
|
-
|
159
|
-
|
155
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/12790328?per_page=200').
|
156
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
157
|
+
to_return(status: 200, body: fixture('show_image'), headers: {})
|
160
158
|
|
161
|
-
stub_request(:post,
|
162
|
-
|
163
|
-
|
164
|
-
|
159
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
160
|
+
with(body: '{"type":"rebuild","image":6376601}',
|
161
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
162
|
+
to_return(status: 200, body: '', headers: {})
|
165
163
|
|
166
|
-
expect($stdin).to receive(:gets).and_return(
|
164
|
+
expect($stdin).to receive(:gets).and_return('y')
|
167
165
|
|
168
|
-
|
169
|
-
|
166
|
+
cli.options = cli.options.merge(id: '12790328', image_id: 12_790_328)
|
167
|
+
cli.rebuild('example.com', 'ubuntu-14-04-x64')
|
170
168
|
|
171
169
|
expect($stdout.string).to eq <<-eos
|
172
170
|
Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
|
@@ -175,36 +173,36 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
|
|
175
173
|
eos
|
176
174
|
end
|
177
175
|
|
178
|
-
it
|
179
|
-
stub_request(:get,
|
180
|
-
|
181
|
-
|
176
|
+
it 'rebuilds a droplet with a name based on an image with an id' do
|
177
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
178
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
179
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
182
180
|
|
183
|
-
stub_request(:get,
|
184
|
-
|
185
|
-
|
181
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
182
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
183
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
186
184
|
|
187
|
-
stub_request(:get,
|
188
|
-
|
189
|
-
|
185
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/12790328?per_page=200').
|
186
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
187
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
190
188
|
|
191
|
-
stub_request(:get,
|
192
|
-
|
193
|
-
|
189
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
190
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
191
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
194
192
|
|
195
|
-
stub_request(:get,
|
196
|
-
|
197
|
-
|
193
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/12790328?per_page=200').
|
194
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
195
|
+
to_return(status: 200, body: fixture('show_image'), headers: {})
|
198
196
|
|
199
|
-
stub_request(:post,
|
200
|
-
|
201
|
-
|
202
|
-
|
197
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
198
|
+
with(body: '{"type":"rebuild","image":6376601}',
|
199
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
200
|
+
to_return(status: 200, body: '', headers: {})
|
203
201
|
|
204
|
-
expect($stdin).to receive(:gets).and_return(
|
202
|
+
expect($stdin).to receive(:gets).and_return('y')
|
205
203
|
|
206
|
-
|
207
|
-
|
204
|
+
cli.options = cli.options.merge(name: 'example.com', image_id: 12_790_328)
|
205
|
+
cli.rebuild('example.com', 'ubuntu-14-04-x64')
|
208
206
|
|
209
207
|
expect($stdout.string).to eq <<-eos
|
210
208
|
Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -213,29 +211,29 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
|
|
213
211
|
eos
|
214
212
|
end
|
215
213
|
|
216
|
-
it
|
217
|
-
stub_request(:get,
|
218
|
-
|
219
|
-
|
214
|
+
it 'rebuilds a droplet with a fuzzy name based on an image with a name' do
|
215
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
216
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
217
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
220
218
|
|
221
|
-
stub_request(:get,
|
222
|
-
|
223
|
-
|
219
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
220
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
221
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
224
222
|
|
225
|
-
stub_request(:get,
|
226
|
-
|
227
|
-
|
223
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
224
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
225
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
228
226
|
|
229
|
-
stub_request(:post,
|
230
|
-
|
231
|
-
|
232
|
-
|
227
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
228
|
+
with(body: '{"type":"rebuild","image":12790328}',
|
229
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
230
|
+
to_return(status: 200, body: '', headers: {})
|
233
231
|
|
234
|
-
expect($stdin).to receive(:gets).and_return(
|
232
|
+
expect($stdin).to receive(:gets).and_return('y')
|
235
233
|
|
236
|
-
|
234
|
+
cli.options = cli.options.merge(image_name: '14.04 x64')
|
237
235
|
|
238
|
-
|
236
|
+
cli.rebuild('example.com', 'ubuntu-14-04-x64')
|
239
237
|
|
240
238
|
expect($stdout.string).to eq <<-eos
|
241
239
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -244,32 +242,32 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
|
|
244
242
|
eos
|
245
243
|
end
|
246
244
|
|
247
|
-
it
|
248
|
-
stub_request(:get,
|
249
|
-
|
250
|
-
|
245
|
+
it 'rebuilds a droplet with an id based on an image with a name' do
|
246
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
247
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
248
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
251
249
|
|
252
|
-
stub_request(:get,
|
253
|
-
|
254
|
-
|
250
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
251
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
252
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
255
253
|
|
256
|
-
stub_request(:get,
|
257
|
-
|
258
|
-
|
254
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/12790328?per_page=200').
|
255
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
256
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
259
257
|
|
260
|
-
stub_request(:get,
|
261
|
-
|
262
|
-
|
258
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
259
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
260
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
263
261
|
|
264
|
-
stub_request(:post,
|
265
|
-
|
266
|
-
|
267
|
-
|
262
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
263
|
+
with(body: '{"type":"rebuild","image":12790328}',
|
264
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
265
|
+
to_return(status: 200, body: '', headers: {})
|
268
266
|
|
269
|
-
expect($stdin).to receive(:gets).and_return(
|
267
|
+
expect($stdin).to receive(:gets).and_return('y')
|
270
268
|
|
271
|
-
|
272
|
-
|
269
|
+
cli.options = cli.options.merge(id: '12790328', image_name: '14.04 x64')
|
270
|
+
cli.rebuild('example.com', '14.04 x64')
|
273
271
|
|
274
272
|
expect($stdout.string).to eq <<-eos
|
275
273
|
Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
|
@@ -278,28 +276,28 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
|
|
278
276
|
eos
|
279
277
|
end
|
280
278
|
|
281
|
-
it
|
282
|
-
stub_request(:get,
|
283
|
-
|
284
|
-
|
279
|
+
it 'rebuilds a droplet with a name based on an image with a name' do
|
280
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
281
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
282
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
285
283
|
|
286
|
-
stub_request(:get,
|
287
|
-
|
288
|
-
|
284
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
285
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
286
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
289
287
|
|
290
|
-
stub_request(:get,
|
291
|
-
|
292
|
-
|
288
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
289
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
290
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
293
291
|
|
294
|
-
stub_request(:post,
|
295
|
-
|
296
|
-
|
297
|
-
|
292
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
293
|
+
with(body: '{"type":"rebuild","image":12790328}',
|
294
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
295
|
+
to_return(status: 200, body: '', headers: {})
|
298
296
|
|
299
|
-
expect($stdin).to receive(:gets).and_return(
|
297
|
+
expect($stdin).to receive(:gets).and_return('y')
|
300
298
|
|
301
|
-
|
302
|
-
|
299
|
+
cli.options = cli.options.merge(name: 'example.com', image_name: '14.04 x64')
|
300
|
+
cli.rebuild('example.com', '14.04 x64')
|
303
301
|
|
304
302
|
expect($stdout.string).to eq <<-eos
|
305
303
|
Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -308,27 +306,26 @@ Warning! Potentially destructive action. Please confirm [y/n]: Queuing rebuild f
|
|
308
306
|
eos
|
309
307
|
end
|
310
308
|
|
311
|
-
it
|
312
|
-
stub_request(:get,
|
313
|
-
|
314
|
-
|
309
|
+
it 'rebuilds a droplet with confirm flag set' do
|
310
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
311
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
312
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
315
313
|
|
316
|
-
stub_request(:get,
|
317
|
-
|
318
|
-
|
314
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
315
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
316
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
319
317
|
|
320
|
-
stub_request(:get,
|
321
|
-
|
322
|
-
|
318
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
319
|
+
with(headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
320
|
+
to_return(status: 200, body: fixture('show_images'), headers: {})
|
323
321
|
|
324
|
-
stub_request(:post,
|
325
|
-
|
326
|
-
|
327
|
-
|
322
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
|
323
|
+
with(body: '{"type":"rebuild","image":12790328}',
|
324
|
+
headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization' => 'Bearer foo', 'Content-Type' => 'application/json', 'User-Agent' => 'Faraday v0.11.0' }).
|
325
|
+
to_return(status: 200, body: '', headers: {})
|
328
326
|
|
329
|
-
|
330
|
-
|
331
|
-
@cli.rebuild("example.com", "14.04 x64")
|
327
|
+
cli.options = cli.options.merge(confirm: 'no')
|
328
|
+
cli.rebuild('example.com', '14.04 x64')
|
332
329
|
|
333
330
|
expect($stdout.string).to eq <<-eos
|
334
331
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -337,5 +334,4 @@ Queuing rebuild for droplet 6918990 (example.com) with image 12790328 (14.04 x64
|
|
337
334
|
eos
|
338
335
|
end
|
339
336
|
end
|
340
|
-
|
341
337
|
end
|