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/ssh_cli_spec.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tugboat::CLI do
|
4
|
-
include_context
|
4
|
+
include_context 'spec'
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe 'ssh' do
|
7
7
|
it "tries to fetch the droplet's IP from the API" do
|
8
|
-
stub_request(:get,
|
9
|
-
|
10
|
-
|
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
|
-
to_return(:
|
14
|
-
allow(Kernel).to receive(:exec).with('ssh', anything
|
12
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
13
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_droplets'))
|
14
|
+
allow(Kernel).to receive(:exec).with('ssh', anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything)
|
15
15
|
|
16
|
-
|
16
|
+
cli.ssh('example.com')
|
17
17
|
end
|
18
18
|
|
19
19
|
it "wait's until droplet active if -w command is given and droplet already active" do
|
20
|
-
stub_request(:get,
|
21
|
-
|
22
|
-
|
20
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
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: '', headers: {})
|
23
23
|
|
24
|
-
stub_request(:get,
|
25
|
-
|
26
|
-
|
24
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?per_page=200').
|
25
|
+
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' }).
|
26
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
27
27
|
|
28
|
-
stub_request(:get,
|
29
|
-
to_return(:
|
30
|
-
allow(Kernel).to receive(:exec).with('ssh', anything
|
28
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
29
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_droplets'))
|
30
|
+
allow(Kernel).to receive(:exec).with('ssh', anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything)
|
31
31
|
|
32
|
-
|
32
|
+
cli.options = cli.options.merge(wait: true)
|
33
33
|
|
34
|
-
|
34
|
+
cli.ssh('example.com')
|
35
35
|
|
36
36
|
expect($stdout.string).to eq <<-eos
|
37
37
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -44,24 +44,24 @@ SShing with options: -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownH
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "wait's until droplet active if -w command is given and droplet eventually active" do
|
47
|
-
stub_request(:get,
|
48
|
-
|
49
|
-
|
47
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
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: '', headers: {})
|
50
50
|
|
51
|
-
stub_request(:get,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?per_page=200').
|
52
|
+
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' }).
|
53
|
+
to_return(
|
54
|
+
{ status: 200, body: fixture('show_droplet_inactive'), headers: {} },
|
55
|
+
status: 200, body: fixture('show_droplet'), headers: {}
|
56
|
+
)
|
57
57
|
|
58
|
-
stub_request(:get,
|
59
|
-
to_return(:
|
60
|
-
allow(Kernel).to receive(:exec).with('ssh', anything
|
58
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
59
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_droplets'))
|
60
|
+
allow(Kernel).to receive(:exec).with('ssh', anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything)
|
61
61
|
|
62
|
-
|
62
|
+
cli.options = cli.options.merge(wait: true)
|
63
63
|
|
64
|
-
|
64
|
+
cli.ssh('example.com')
|
65
65
|
|
66
66
|
expect($stdout.string).to eq <<-eos
|
67
67
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -73,22 +73,21 @@ SShing with options: -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownH
|
|
73
73
|
eos
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
77
|
-
stub_request(:get,
|
78
|
-
|
79
|
-
|
76
|
+
it 'does not allow ssh into a droplet that is inactive' do
|
77
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
78
|
+
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' }).
|
79
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
80
80
|
|
81
|
-
stub_request(:get,
|
82
|
-
to_return(:
|
81
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
82
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_droplets'))
|
83
83
|
allow(Kernel).to receive(:exec)
|
84
84
|
|
85
|
-
expect {
|
85
|
+
expect { cli.ssh('example3.com') }.to raise_error(SystemExit)
|
86
86
|
|
87
87
|
expect($stdout.string).to eq <<-eos
|
88
88
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
|
89
89
|
Droplet must be on for this operation to be successful.
|
90
90
|
eos
|
91
91
|
end
|
92
|
-
|
93
92
|
end
|
94
93
|
end
|
data/spec/cli/start_cli_spec.rb
CHANGED
@@ -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 'start' do
|
7
|
+
it 'starts the 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(:post,
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/3164444/actions').
|
17
|
+
with(body: '{"type":"power_on"}',
|
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('droplet_start_response'), headers: {})
|
20
20
|
|
21
|
-
|
21
|
+
cli.start('example3.com')
|
22
22
|
|
23
23
|
expect($stdout.string).to eq <<-eos
|
24
24
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
|
@@ -26,22 +26,21 @@ Queuing start for 3164444 (example3.com)...Start complete!
|
|
26
26
|
eos
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
stub_request(:get,
|
31
|
-
|
32
|
-
|
29
|
+
it 'starts the droplet with an id' do
|
30
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
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_droplets'), headers: {})
|
33
33
|
|
34
|
-
stub_request(:get,
|
35
|
-
|
36
|
-
|
34
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/3164494?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_droplet_inactive'))
|
37
37
|
|
38
|
-
stub_request(:post,
|
39
|
-
|
40
|
-
|
38
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/3164494/actions').
|
39
|
+
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' }).
|
40
|
+
to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_droplet_inactive'))
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
@cli.start
|
42
|
+
cli.options = cli.options.merge(id: '3164494')
|
43
|
+
cli.start
|
45
44
|
|
46
45
|
expect($stdout.string).to eq <<-eos
|
47
46
|
Droplet id provided. Finding Droplet...done\e[0m, 3164494 (example.com)
|
@@ -49,23 +48,22 @@ Queuing start for 3164494 (example.com)...Start complete!
|
|
49
48
|
eos
|
50
49
|
end
|
51
50
|
|
51
|
+
it 'starts the droplet with a name' do
|
52
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
53
|
+
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' }).
|
54
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
|
57
|
-
|
58
|
-
stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200").
|
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 => 200, :body => fixture('show_droplets'), :headers => {})
|
56
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
57
|
+
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' }).
|
58
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
61
59
|
|
62
|
-
stub_request(:post,
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
stub_request(:post, 'https://api.digitalocean.com/v2/droplets/3164444/actions').
|
61
|
+
with(body: '{"type":"power_on"}',
|
62
|
+
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' }).
|
63
|
+
to_return(status: 200, body: fixture('droplet_start_response'), headers: {})
|
66
64
|
|
67
|
-
|
68
|
-
|
65
|
+
cli.options = cli.options.merge(name: 'example3.com')
|
66
|
+
cli.start
|
69
67
|
|
70
68
|
expect($stdout.string).to eq <<-eos
|
71
69
|
Droplet name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
|
@@ -73,24 +71,22 @@ Queuing start for 3164444 (example3.com)...Start complete!
|
|
73
71
|
eos
|
74
72
|
end
|
75
73
|
|
76
|
-
it
|
77
|
-
stub_request(:get,
|
78
|
-
|
79
|
-
|
74
|
+
it 'does not start a droplet that is inactive' do
|
75
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
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_droplets'), headers: {})
|
80
78
|
|
81
|
-
stub_request(:get,
|
82
|
-
|
83
|
-
|
79
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&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_droplets'), headers: {})
|
84
82
|
|
85
|
-
|
86
|
-
expect {
|
83
|
+
cli.options = cli.options.merge(name: 'example.com')
|
84
|
+
expect { cli.start }.to raise_error(SystemExit)
|
87
85
|
|
88
86
|
expect($stdout.string).to eq <<-eos
|
89
87
|
Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
90
88
|
Droplet must be off for this operation to be successful.
|
91
89
|
eos
|
92
|
-
|
93
|
-
|
94
90
|
end
|
95
91
|
end
|
96
92
|
end
|
data/spec/cli/verify_cli_spec.rb
CHANGED
@@ -1,42 +1,39 @@
|
|
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 'verify' do
|
7
|
+
it 'returns confirmation text when verify passes' 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
|
-
|
12
|
+
cli.verify
|
13
13
|
expect($stdout.string).to eq "Authentication with DigitalOcean was successful.\n"
|
14
|
-
expect(a_request(:get,
|
14
|
+
expect(a_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1')).to have_been_made
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
stub_request(:get,
|
19
|
-
|
20
|
-
|
17
|
+
it 'returns error when verify fails' do
|
18
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
19
|
+
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' }).
|
20
|
+
to_return(headers: { 'Content-Type' => 'text/html' }, status: 401, body: fixture('401'))
|
21
21
|
|
22
|
-
expect {
|
23
|
-
expect($stdout.string).to include
|
24
|
-
expect(a_request(:get,
|
22
|
+
expect { cli.verify }.to raise_error(SystemExit)
|
23
|
+
expect($stdout.string).to include 'Failed to connect to DigitalOcean. Reason given from API: unauthorized - Unable to authenticate you.'
|
24
|
+
expect(a_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1')).to have_been_made
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
stub_request(:get,
|
29
|
-
with(:
|
30
|
-
to_return(:
|
27
|
+
it 'returns error string when verify fails and a non-json reponse is given' do
|
28
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
29
|
+
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' }).
|
30
|
+
to_return(headers: { 'Content-Type' => 'text/html' }, status: 500, body: fixture('500', 'html'))
|
31
31
|
|
32
|
-
expect {
|
33
|
-
expect($stdout.string).to include
|
32
|
+
expect { cli.verify }.to raise_error(SystemExit)
|
33
|
+
expect($stdout.string).to include 'Authentication with DigitalOcean failed at an early stage'
|
34
34
|
expect($stdout.string).to include "<title>DigitalOcean - Seems we've encountered a problem!</title>"
|
35
35
|
# TODO: Make it so this doesnt barf up a huge HTML file...
|
36
|
-
expect(a_request(:get,
|
36
|
+
expect(a_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1')).to have_been_made
|
37
37
|
end
|
38
|
-
|
39
38
|
end
|
40
|
-
|
41
39
|
end
|
42
|
-
|
@@ -1,16 +1,14 @@
|
|
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 'version' do
|
7
|
+
it 'shows the correct version' do
|
8
|
+
cli.options = cli.options.merge(version: true)
|
9
|
+
cli.version
|
8
10
|
|
9
|
-
|
10
|
-
@cli.version
|
11
|
-
|
12
|
-
expect($stdout.string.chomp).to eq("Tugboat #{Tugboat::VERSION.to_s}")
|
11
|
+
expect($stdout.string.chomp).to eq("Tugboat #{Tugboat::VERSION}")
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
16
|
-
|
data/spec/cli/wait_cli_spec.rb
CHANGED
@@ -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 'wait' do
|
7
|
+
it 'waits for 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(:get,
|
17
|
-
|
18
|
-
|
16
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?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_droplet'), headers: {})
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
cli.options = cli.options.merge(state: 'active')
|
21
|
+
cli.wait('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)
|
@@ -26,24 +26,24 @@ Waiting for droplet to become active..done\e[0m (0s)
|
|
26
26
|
eos
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
stub_request(:get,
|
31
|
-
|
32
|
-
|
29
|
+
it 'loops whilst it waits for state' do
|
30
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
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_droplets'), headers: {})
|
33
33
|
|
34
|
-
stub_request(:get,
|
35
|
-
|
36
|
-
|
34
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&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(status: 200, body: fixture('show_droplets'), headers: {})
|
37
37
|
|
38
|
-
stub_request(:get,
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?per_page=200').
|
39
|
+
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' }).
|
40
|
+
to_return(
|
41
|
+
{ status: 200, body: fixture('show_droplet_inactive'), headers: {} },
|
42
|
+
status: 200, body: fixture('show_droplet'), headers: {}
|
43
|
+
)
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
cli.options = cli.options.merge(state: 'active')
|
46
|
+
cli.wait('example.com')
|
47
47
|
|
48
48
|
expect($stdout.string).to eq <<-eos
|
49
49
|
Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
@@ -51,17 +51,17 @@ Waiting for droplet to become active...done\e[0m (2s)
|
|
51
51
|
eos
|
52
52
|
end
|
53
53
|
|
54
|
-
it
|
55
|
-
stub_request(:get,
|
56
|
-
|
57
|
-
|
54
|
+
it 'waits for a droplet with an id' do
|
55
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
56
|
+
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' }).
|
57
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
58
58
|
|
59
|
-
stub_request(:get,
|
60
|
-
|
61
|
-
|
59
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?per_page=200').
|
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_droplet'), headers: {})
|
62
62
|
|
63
|
-
|
64
|
-
|
63
|
+
cli.options = cli.options.merge(id: '6918990', state: 'active')
|
64
|
+
cli.wait
|
65
65
|
|
66
66
|
expect($stdout.string).to eq <<-eos
|
67
67
|
Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
|
@@ -69,28 +69,26 @@ Waiting for droplet to become active..done\e[0m (0s)
|
|
69
69
|
eos
|
70
70
|
end
|
71
71
|
|
72
|
-
it
|
73
|
-
stub_request(:get,
|
74
|
-
|
75
|
-
|
72
|
+
it 'waits for a droplet with a name' do
|
73
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
|
74
|
+
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' }).
|
75
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
76
76
|
|
77
|
-
stub_request(:get,
|
78
|
-
|
79
|
-
|
77
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=200').
|
78
|
+
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' }).
|
79
|
+
to_return(status: 200, body: fixture('show_droplets'), headers: {})
|
80
80
|
|
81
|
-
stub_request(:get,
|
82
|
-
|
83
|
-
|
81
|
+
stub_request(:get, 'https://api.digitalocean.com/v2/droplets/6918990?per_page=200').
|
82
|
+
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' }).
|
83
|
+
to_return(status: 200, body: fixture('show_droplet'), headers: {})
|
84
84
|
|
85
|
-
|
86
|
-
|
85
|
+
cli.options = cli.options.merge(name: 'example.com', state: 'active')
|
86
|
+
cli.wait
|
87
87
|
|
88
88
|
expect($stdout.string).to eq <<-eos
|
89
89
|
Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
|
90
90
|
Waiting for droplet to become active..done\e[0m (0s)
|
91
91
|
eos
|
92
92
|
end
|
93
|
-
|
94
93
|
end
|
95
|
-
|
96
94
|
end
|