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
data/spec/cli/config_cli_spec.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
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
|
-
|
9
|
-
@cli.config
|
6
|
+
describe 'config' do
|
7
|
+
it 'shows the full config' do
|
8
|
+
cli.config
|
10
9
|
|
11
10
|
expect($stdout.string).to eq <<-eos
|
12
11
|
Current Config\x20
|
@@ -29,12 +28,11 @@ defaults:
|
|
29
28
|
eos
|
30
29
|
end
|
31
30
|
|
32
|
-
it
|
33
|
-
|
34
|
-
|
35
|
-
@cli.config
|
31
|
+
it 'hides sensitive data if option given' do
|
32
|
+
cli.options = cli.options.merge(hide: true)
|
33
|
+
cli.config
|
36
34
|
|
37
|
-
|
35
|
+
expect($stdout.string).to eq <<-eos
|
38
36
|
Current Config (Keys Redacted)
|
39
37
|
Path: #{Dir.pwd}/tmp/tugboat
|
40
38
|
---
|
@@ -56,4 +54,3 @@ defaults:
|
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
59
|
-
|
data/spec/cli/create_cli_spec.rb
CHANGED
@@ -1,82 +1,76 @@
|
|
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(:post,
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
describe 'create a droplet' do
|
7
|
+
it 'with a name, uses defaults from configuration' do
|
8
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
|
9
|
+
with(body: '{"name":"foo","size":"512mb","image":"ubuntu-14-04-x64","region":"nyc2","ssh_keys":["1234"],"private_networking":"false","backups_enabled":"false","ipv6":"false","user_data":null}',
|
10
|
+
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' }).
|
11
|
+
to_return(status: 200, body: fixture('create_droplet'), headers: {})
|
12
12
|
|
13
|
-
|
13
|
+
cli.create(droplet_name)
|
14
14
|
|
15
15
|
expect($stdout.string).to eq <<-eos
|
16
16
|
Queueing creation of droplet '#{droplet_name}'...Droplet created!
|
17
17
|
eos
|
18
18
|
end
|
19
19
|
|
20
|
-
it
|
21
|
-
stub_request(:post,
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
it 'with args does not use defaults from configuration' do
|
21
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
|
22
|
+
with(body: '{"name":"example.com","size":"1gb","image":"ubuntu-12-04-x64","region":"nyc3","ssh_keys":["foo_bar_key"],"private_networking":"false","backups_enabled":"false","ipv6":"false","user_data":null}',
|
23
|
+
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' }).
|
24
|
+
to_return(status: 200, body: fixture('create_droplet'), headers: {})
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
cli.options = cli.options.merge(image: 'ubuntu-12-04-x64', size: '1gb', region: 'nyc3', keys: 'foo_bar_key')
|
27
|
+
cli.create('example.com')
|
28
28
|
|
29
29
|
expect($stdout.string).to eq <<-eos
|
30
30
|
Queueing creation of droplet 'example.com'...Droplet created!
|
31
31
|
eos
|
32
|
-
|
33
32
|
end
|
34
33
|
|
35
|
-
it
|
36
|
-
stub_request(:post,
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
it 'with ip6 enable args' do
|
35
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
|
36
|
+
with(body: '{"name":"example.com","size":"512mb","image":"ubuntu-14-04-x64","region":"nyc2","ssh_keys":["1234"],"private_networking":"false","backups_enabled":"false","ipv6":"true","user_data":null}',
|
37
|
+
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' }).
|
38
|
+
to_return(status: 200, body: fixture('create_droplet'), headers: {})
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
cli.options = cli.options.merge(ip6: 'true')
|
41
|
+
cli.create('example.com')
|
43
42
|
|
44
43
|
expect($stdout.string).to eq <<-eos
|
45
44
|
Queueing creation of droplet 'example.com'...Droplet created!
|
46
45
|
eos
|
47
|
-
|
48
46
|
end
|
49
47
|
|
50
|
-
it
|
51
|
-
stub_request(:post,
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
it 'with user data args' do
|
49
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
|
50
|
+
with(body: '{"name":"example.com","size":"512mb","image":"ubuntu-14-04-x64","region":"nyc2","ssh_keys":["1234"],"private_networking":"false","backups_enabled":"false","ipv6":"false","user_data":"#!/bin/bash\\n\\necho \\"Hello world\\""}',
|
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: fixture('create_droplet'), headers: {})
|
55
53
|
|
56
|
-
|
57
|
-
|
54
|
+
cli.options = cli.options.merge(user_data: project_path + '/spec/fixtures/user_data.sh')
|
55
|
+
cli.create('example.com')
|
58
56
|
|
59
57
|
expect($stdout.string).to eq <<-eos
|
60
58
|
Queueing creation of droplet 'example.com'...Droplet created!
|
61
59
|
eos
|
62
|
-
|
63
60
|
end
|
64
61
|
|
65
|
-
it
|
66
|
-
|
67
|
-
expect {
|
62
|
+
it 'fails when user data file does not exist' do
|
63
|
+
cli.options = cli.options.merge(user_data: '/foo/bar/baz.sh')
|
64
|
+
expect { cli.create('example.com') }.to raise_error(SystemExit)
|
68
65
|
|
69
66
|
expect($stdout.string).to eq <<-eos
|
70
67
|
Queueing creation of droplet 'example.com'...Could not find file: /foo/bar/baz.sh, check your user_data setting
|
71
68
|
eos
|
72
|
-
|
73
69
|
end
|
74
70
|
|
75
71
|
context "doesn't create a droplet when mistyping help command" do
|
76
|
-
|
77
|
-
['help','--help','-h'].each do |help_attempt|
|
72
|
+
['help', '--help', '-h'].each do |help_attempt|
|
78
73
|
it "tugboat create #{help_attempt}" do
|
79
|
-
|
80
74
|
help_text = <<-eos
|
81
75
|
Usage:
|
82
76
|
rspec create NAME
|
@@ -95,19 +89,19 @@ Options:
|
|
95
89
|
Create a droplet.
|
96
90
|
eos
|
97
91
|
|
98
|
-
|
92
|
+
cli.create(help_attempt)
|
99
93
|
expect($stdout.string).to eq help_text
|
100
94
|
end
|
101
95
|
end
|
102
96
|
end
|
103
97
|
|
104
|
-
it
|
105
|
-
stub_request(:post,
|
106
|
-
|
107
|
-
|
108
|
-
|
98
|
+
it 'does not clobber named droplets that contain the word help' do
|
99
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets').
|
100
|
+
with(body: '{"name":"somethingblahblah--help","size":"512mb","image":"ubuntu-14-04-x64","region":"nyc2","ssh_keys":["1234"],"private_networking":"false","backups_enabled":"false","ipv6":"false","user_data":null}',
|
101
|
+
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' }).
|
102
|
+
to_return(status: 200, body: fixture('create_droplet'), headers: {})
|
109
103
|
|
110
|
-
|
104
|
+
cli.create('somethingblahblah--help')
|
111
105
|
|
112
106
|
expect($stdout.string).to eq <<-eos
|
113
107
|
Queueing creation of droplet 'somethingblahblah--help'...Droplet created!
|
data/spec/cli/debug_cli_spec.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
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
|
-
before
|
6
|
+
describe 'DEBUG=1' do
|
7
|
+
before do
|
8
8
|
allow(ENV).to receive(:[]).with('HOME').and_return('/tmp/fake_home')
|
9
9
|
allow(ENV).to receive(:[]).with('DEBUG').and_return(1)
|
10
10
|
allow(ENV).to receive(:[]).with('http_proxy').and_return(nil)
|
11
11
|
allow(ENV).to receive(:[]).with('DO_API_TOKEN').and_return(nil)
|
12
|
+
allow(ENV).to receive(:[]).with('THOR_SHELL').and_return(nil)
|
12
13
|
end
|
13
14
|
|
14
|
-
it
|
15
|
-
stub_request(:get,
|
16
|
-
with(:
|
17
|
-
to_return(:
|
15
|
+
it 'gives full faraday logs' do
|
16
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
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_droplets'), headers: {})
|
18
19
|
|
19
|
-
stub_request(:get,
|
20
|
-
with(:
|
21
|
-
to_return(:
|
20
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
21
|
+
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' }).
|
22
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
22
23
|
|
23
|
-
|
24
|
+
cli.droplets
|
24
25
|
|
25
|
-
expect($stdout.string).to include
|
26
|
-
expect($stdout.string).to include
|
26
|
+
expect($stdout.string).to include 'Started GET request to: https://api.digitalocean.com/v2/droplets?page=1&per_page=200'
|
27
|
+
expect($stdout.string).to include 'DEBUG -- : Request Headers:'
|
27
28
|
|
28
|
-
expect($stdout.string).to include
|
29
|
+
expect($stdout.string).to include 'Bearer foo'
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
describe
|
33
|
-
before
|
33
|
+
describe 'DEBUG=2' do
|
34
|
+
before do
|
34
35
|
allow(ENV).to receive(:[]).with('HOME').and_return('/tmp/fake_home')
|
35
36
|
allow(ENV).to receive(:[]).with('DEBUG').and_return(2)
|
36
37
|
allow(ENV).to receive(:[]).with('http_proxy').and_return(nil)
|
37
38
|
allow(ENV).to receive(:[]).with('DO_API_TOKEN').and_return(nil)
|
39
|
+
allow(ENV).to receive(:[]).with('THOR_SHELL').and_return(nil)
|
38
40
|
end
|
39
41
|
|
40
|
-
it
|
41
|
-
stub_request(:get,
|
42
|
-
with(:
|
43
|
-
to_return(:
|
42
|
+
it 'gives full faraday logs with redacted API keys' do
|
43
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
44
|
+
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' }).
|
45
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
44
46
|
|
45
|
-
stub_request(:get,
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
48
|
+
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' }).
|
49
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
50
|
+
cli.droplets
|
49
51
|
|
50
|
-
expect($stdout.string).to include
|
51
|
-
expect($stdout.string).to include
|
52
|
+
expect($stdout.string).to include 'Started GET request to: https://api.digitalocean.com/v2/droplets?page=1&per_page=200'
|
53
|
+
expect($stdout.string).to include 'DEBUG -- : Request Headers:'
|
52
54
|
|
53
|
-
expect($stdout.string).
|
55
|
+
expect($stdout.string).not_to include 'Bearer foo'
|
54
56
|
end
|
55
57
|
end
|
56
|
-
|
57
58
|
end
|
58
|
-
|
@@ -1,89 +1,88 @@
|
|
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 'destroy' do
|
7
|
+
it 'destroys a droplet 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(:delete,
|
17
|
-
|
18
|
-
|
16
|
+
stub_request(:delete, 'https://api.digitalocean.com/v2/droplets/6918990').
|
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: 204, body: '', headers: {})
|
19
19
|
|
20
|
-
expect($stdin).to receive(:gets).and_return(
|
20
|
+
expect($stdin).to receive(:gets).and_return('y')
|
21
21
|
|
22
|
-
|
22
|
+
cli.destroy('example.com')
|
23
23
|
|
24
24
|
expect($stdout.string).to eq <<-eos
|
25
25
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy for 6918990 (example.com)...Deletion Successful!
|
26
26
|
eos
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
stub_request(:get,
|
31
|
-
|
32
|
-
|
29
|
+
it 'destroys a droplet with an id' do
|
30
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?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(status: 200, body: fixture('show_droplet'), headers: {})
|
33
33
|
|
34
|
-
stub_request(:delete,
|
35
|
-
|
36
|
-
|
34
|
+
stub_request(:delete, 'https://api.digitalocean.com/v2/droplets/6918990').
|
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(status: 204, body: '', headers: {})
|
37
37
|
|
38
|
-
expect($stdin).to receive(:gets).and_return(
|
38
|
+
expect($stdin).to receive(:gets).and_return('y')
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
cli.options = cli.options.merge(id: '6918990')
|
41
|
+
cli.destroy
|
42
42
|
|
43
43
|
expect($stdout.string).to eq <<-eos
|
44
44
|
Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy for 6918990 (example.com)...Deletion Successful!
|
45
45
|
eos
|
46
46
|
end
|
47
47
|
|
48
|
+
it 'destroys a droplet with a name' do
|
49
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
50
|
+
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' }).
|
51
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
|
53
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&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(status: 200, body: fixture('show_droplets'), headers: {})
|
53
56
|
|
54
|
-
stub_request(:
|
55
|
-
|
56
|
-
|
57
|
+
stub_request(:delete, 'https://api.digitalocean.com/v2/droplets/6918990').
|
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(status: 204, body: '', headers: {})
|
57
60
|
|
58
|
-
|
59
|
-
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'}).
|
60
|
-
to_return(:status => 204, :body => "", :headers => {})
|
61
|
+
expect($stdin).to receive(:gets).and_return('y')
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
@cli.options = @cli.options.merge(:name => 'example.com')
|
65
|
-
@cli.destroy
|
63
|
+
cli.options = cli.options.merge(name: 'example.com')
|
64
|
+
cli.destroy
|
66
65
|
|
67
66
|
expect($stdout.string).to eq <<-eos
|
68
67
|
Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy for 6918990 (example.com)...Deletion Successful!
|
69
68
|
eos
|
70
69
|
end
|
71
70
|
|
72
|
-
it
|
73
|
-
stub_request(:get,
|
74
|
-
|
75
|
-
|
71
|
+
it 'destroys a droplet with confirm flag set' do
|
72
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
73
|
+
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' }).
|
74
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
76
75
|
|
77
|
-
stub_request(:get,
|
78
|
-
with(:
|
79
|
-
to_return(:
|
76
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&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(status: 200, body: fixture('show_droplets'), headers: {})
|
80
79
|
|
81
|
-
stub_request(:delete,
|
82
|
-
with(:
|
83
|
-
to_return(:
|
80
|
+
stub_request(:delete, 'https://api.digitalocean.com/v2/droplets/6918990').
|
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: 204, body: '', headers: {})
|
84
83
|
|
85
|
-
|
86
|
-
|
84
|
+
cli.options = cli.options.merge(name: 'example.com', confirm: true)
|
85
|
+
cli.destroy
|
87
86
|
|
88
87
|
expect($stdout.string).to eq <<-eos
|
89
88
|
Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -91,23 +90,22 @@ Queuing destroy for 6918990 (example.com)...Deletion Successful!
|
|
91
90
|
eos
|
92
91
|
end
|
93
92
|
|
94
|
-
it
|
95
|
-
stub_request(:get,
|
96
|
-
with(:
|
97
|
-
to_return(:
|
93
|
+
it 'does not destroy a droplet if no is chosen' do
|
94
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
95
|
+
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' }).
|
96
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
98
97
|
|
99
|
-
stub_request(:get,
|
100
|
-
with(:
|
101
|
-
to_return(:
|
98
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
99
|
+
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' }).
|
100
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
102
101
|
|
103
|
-
$stdin.should_receive(:gets).and_return(
|
102
|
+
$stdin.should_receive(:gets).and_return('n')
|
104
103
|
|
105
|
-
expect {
|
104
|
+
expect { cli.destroy('example.com') }.to raise_error(SystemExit)
|
106
105
|
|
107
106
|
expect($stdout.string).to eq <<-eos
|
108
107
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)\nWarning! Potentially destructive action. Please confirm [y/n]: Aborted due to user request.
|
109
108
|
eos
|
110
109
|
end
|
111
110
|
end
|
112
|
-
|
113
111
|
end
|
@@ -1,82 +1,79 @@
|
|
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 'destroy image' do
|
7
|
+
it 'destroys 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(status: 200, body: fixture('show_images_global'), headers: {})
|
11
11
|
|
12
|
-
stub_request(:delete,
|
13
|
-
|
14
|
-
|
12
|
+
stub_request(:delete, 'https://api.digitalocean.com/v2/images/6376601').
|
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: 204, body: '', headers: {})
|
15
15
|
|
16
|
-
expect($stdin).to receive(:gets).and_return(
|
16
|
+
expect($stdin).to receive(:gets).and_return('y')
|
17
17
|
|
18
|
-
|
18
|
+
cli.destroy_image('My application image')
|
19
19
|
|
20
20
|
expect($stdout.string).to eq <<-eos
|
21
21
|
Image fuzzy name provided. Finding image ID...done\e[0m, 6376601 (My application image)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy image for 6376601 (My application image)...Image deletion successful!
|
22
22
|
eos
|
23
23
|
end
|
24
24
|
|
25
|
-
it
|
26
|
-
stub_request(:get,
|
27
|
-
|
28
|
-
|
25
|
+
it 'destroys an image with an id' do
|
26
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images/6376601?per_page=200').
|
27
|
+
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' }).
|
28
|
+
to_return(status: 200, body: fixture('show_image'), headers: {})
|
29
29
|
|
30
|
-
stub_request(:delete,
|
31
|
-
|
32
|
-
|
30
|
+
stub_request(:delete, 'https://api.digitalocean.com/v2/images/6376601').
|
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(status: 204, body: '', headers: {})
|
33
33
|
|
34
|
-
expect($stdin).to receive(:gets).and_return(
|
34
|
+
expect($stdin).to receive(:gets).and_return('y')
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
cli.options = cli.options.merge(id: 6_376_601)
|
37
|
+
cli.destroy_image
|
38
38
|
|
39
39
|
expect($stdout.string).to eq <<-eos
|
40
40
|
Image id provided. Finding Image...done\e[0m, 6376601 (My application image)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy image for 6376601 (My application image)...Image deletion successful!
|
41
41
|
eos
|
42
|
-
|
43
|
-
|
42
|
+
end
|
44
43
|
|
45
|
-
it
|
46
|
-
stub_request(:get,
|
47
|
-
|
48
|
-
|
44
|
+
it 'destroys an image with a name' do
|
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_global'), headers: {})
|
49
48
|
|
50
|
-
stub_request(:delete,
|
51
|
-
|
52
|
-
|
49
|
+
stub_request(:delete, 'https://api.digitalocean.com/v2/images/6376601').
|
50
|
+
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' }).
|
51
|
+
to_return(status: 204, body: '', headers: {})
|
53
52
|
|
54
|
-
expect($stdin).to receive(:gets).and_return(
|
53
|
+
expect($stdin).to receive(:gets).and_return('y')
|
55
54
|
|
56
|
-
|
57
|
-
|
55
|
+
cli.options = cli.options.merge(name: 'My application image')
|
56
|
+
cli.destroy_image
|
58
57
|
|
59
58
|
expect($stdout.string).to eq "Image name provided. Finding Image...done\e[0m, 6376601 (My application image)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy image for 6376601 (My application image)...Image deletion successful!\n"
|
60
59
|
end
|
61
60
|
|
61
|
+
it 'destroys an image with confirm flag set' do
|
62
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/images?per_page=200').
|
63
|
+
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' }).
|
64
|
+
to_return(status: 200, body: fixture('show_images_global'), headers: {})
|
62
65
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
to_return(:status => 200, :body => fixture('show_images_global'), :headers => {})
|
66
|
+
stub_request(:delete, 'https://api.digitalocean.com/v2/images/6376601').
|
67
|
+
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' }).
|
68
|
+
to_return(status: 204, body: '', headers: {})
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@cli.options = @cli.options.merge(:name => "My application image")
|
73
|
-
@cli.options = @cli.options.merge(:confirm => true)
|
74
|
-
@cli.destroy_image("NLP Final")
|
70
|
+
cli.options = cli.options.merge(name: 'My application image')
|
71
|
+
cli.options = cli.options.merge(confirm: true)
|
72
|
+
cli.destroy_image('NLP Final')
|
75
73
|
|
76
74
|
expect($stdout.string).to eq <<-eos
|
77
75
|
Image name provided. Finding Image...done\e[0m, 6376601 (My application image)\nQueuing destroy image for 6376601 (My application image)...Image deletion successful!
|
78
76
|
eos
|
79
77
|
end
|
80
78
|
end
|
81
|
-
|
82
79
|
end
|