tugboat 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -1
  3. data/CODE_OF_CONDUCT.md +46 -0
  4. data/lib/tugboat/cli.rb +7 -1
  5. data/lib/tugboat/config.rb +11 -1
  6. data/lib/tugboat/middleware.rb +2 -0
  7. data/lib/tugboat/middleware/ask_for_credentials.rb +2 -1
  8. data/lib/tugboat/middleware/base.rb +31 -13
  9. data/lib/tugboat/middleware/check_snapshot_parameters.rb +16 -0
  10. data/lib/tugboat/middleware/info_droplet.rb +2 -2
  11. data/lib/tugboat/middleware/inject_client.rb +10 -1
  12. data/lib/tugboat/middleware/list_droplets.rb +5 -3
  13. data/lib/tugboat/version.rb +1 -1
  14. data/spec/cli/add_key_spec.rb +7 -9
  15. data/spec/cli/authorize_cli_spec.rb +4 -34
  16. data/spec/cli/config_cli_spec.rb +10 -5
  17. data/spec/cli/create_cli_spec.rb +20 -17
  18. data/spec/cli/debug_cli_spec.rb +11 -12
  19. data/spec/cli/destroy_cli_spec.rb +35 -12
  20. data/spec/cli/destroy_image_cli_spec.rb +12 -10
  21. data/spec/cli/droplets_cli_spec.rb +74 -48
  22. data/spec/cli/env_variable_spec.rb +4 -4
  23. data/spec/cli/halt_cli_spec.rb +16 -13
  24. data/spec/cli/help_cli_spec.rb +4 -4
  25. data/spec/cli/images_cli_spec.rb +9 -7
  26. data/spec/cli/info_cli_spec.rb +120 -50
  27. data/spec/cli/info_image_cli_spec.rb +24 -23
  28. data/spec/cli/keys_cli_spec.rb +3 -3
  29. data/spec/cli/password_reset_cli_spec.rb +12 -12
  30. data/spec/cli/rebuild_cli_spec.rb +31 -24
  31. data/spec/cli/regions_cli_spec.rb +3 -3
  32. data/spec/cli/resize_cli_spec.rb +16 -16
  33. data/spec/cli/restart_cli_spec.rb +32 -11
  34. data/spec/cli/sizes_cli_spec.rb +3 -3
  35. data/spec/cli/snapshot_cli_spec.rb +25 -9
  36. data/spec/cli/ssh_cli_spec.rb +10 -10
  37. data/spec/cli/start_cli_spec.rb +15 -15
  38. data/spec/cli/verify_cli_spec.rb +4 -7
  39. data/spec/cli/version_cli_spec.rb +1 -2
  40. data/spec/cli/wait_cli_spec.rb +16 -16
  41. data/spec/config_spec.rb +7 -1
  42. data/spec/fixtures/show_droplets.json +7 -4
  43. data/spec/fixtures/show_droplets_paginated_first.json +10 -7
  44. data/spec/fixtures/show_droplets_paginated_last.json +11 -5
  45. data/spec/fixtures/show_droplets_private_ip.json +7 -4
  46. data/spec/middleware/base_spec.rb +1 -2
  47. data/spec/middleware/check_configuration_spec.rb +1 -1
  48. data/spec/middleware/check_credentials_spec.rb +1 -1
  49. data/spec/middleware/check_droplet_active_spec.rb +1 -1
  50. data/spec/middleware/check_droplet_inactive_spec.rb +1 -1
  51. data/spec/middleware/find_droplet_spec.rb +3 -5
  52. data/spec/middleware/find_image_spec.rb +3 -5
  53. data/spec/middleware/ssh_droplet_spec.rb +5 -10
  54. data/spec/shared/environment.rb +2 -18
  55. data/tugboat.gemspec +1 -2
  56. metadata +8 -6
@@ -18,12 +18,12 @@ describe Tugboat::CLI do
18
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.9.2' }).
19
19
  to_return(status: 200, body: fixture('restart_response'), headers: {})
20
20
 
21
- cli.restart('example.com')
22
-
23
- expect($stdout.string).to eq <<-eos
21
+ expected_string = <<-eos
24
22
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
25
23
  Queuing restart for 6918990 (example.com)...Restart complete!
26
24
  eos
25
+
26
+ expect { cli.restart('example.com') }.to output(expected_string).to_stdout
27
27
  end
28
28
 
29
29
  it 'restarts a droplet hard when the hard option is used' do
@@ -41,12 +41,13 @@ Queuing restart for 6918990 (example.com)...Restart complete!
41
41
  to_return(status: 200, body: '', headers: {})
42
42
 
43
43
  cli.options = cli.options.merge(hard: true)
44
- cli.restart('example.com')
45
44
 
46
- expect($stdout.string).to eq <<-eos
45
+ expected_string = <<-eos
47
46
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
48
47
  Queuing hard restart for 6918990 (example.com)...Restart complete!
49
48
  eos
49
+
50
+ expect { cli.restart('example.com') }.to output(expected_string).to_stdout
50
51
  end
51
52
 
52
53
  it 'with an id' do
@@ -64,12 +65,13 @@ Queuing hard restart for 6918990 (example.com)...Restart complete!
64
65
  to_return(status: 200, body: fixture('restart_response'), headers: {})
65
66
 
66
67
  cli.options = cli.options.merge(id: '6918990')
67
- cli.restart
68
68
 
69
- expect($stdout.string).to eq <<-eos
69
+ expected_string = <<-eos
70
70
  Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
71
71
  Queuing restart for 6918990 (example.com)...Restart complete!
72
72
  eos
73
+
74
+ expect { cli.restart }.to output(expected_string).to_stdout
73
75
  end
74
76
 
75
77
  it 'with a name' do
@@ -86,13 +88,32 @@ Queuing restart for 6918990 (example.com)...Restart complete!
86
88
  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' }).
87
89
  to_return(status: 200, body: fixture('restart_response'), headers: {})
88
90
 
89
- cli.options = cli.options.merge(name: 'example.com')
90
- cli.restart
91
-
92
- expect($stdout.string).to eq <<-eos
91
+ expected_string = <<-eos
93
92
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
94
93
  Queuing restart for 6918990 (example.com)...Restart complete!
95
94
  eos
95
+
96
+ cli.options = cli.options.merge(name: 'example.com')
97
+ expect { cli.restart }.to output(expected_string).to_stdout
98
+ end
99
+
100
+ it 'raises SystemExit when a request fails' 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.9.2' }).
103
+ to_return(status: 200, body: fixture('show_droplets'), headers: {})
104
+
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.9.2' }).
107
+ to_return(status: 200, body: fixture('show_droplets'), headers: { 'Content-Type' => 'application/json' })
108
+
109
+ stub_request(:post, 'https://api.digitalocean.com/v2/droplets/6918990/actions').
110
+ with(body: '{"type":"reboot"}',
111
+ 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' }).
112
+ to_return(headers: { 'Content-Type' => 'application/json' }, status: 500, body: '{"status":"ERROR","message":"Some error"}')
113
+
114
+ cli.options = cli.options.merge(name: 'example.com')
115
+
116
+ expect { cli.restart }.to raise_error(SystemExit).and output(%r{Failed to restart Droplet: Some error}).to_stdout
96
117
  end
97
118
  end
98
119
  end
@@ -9,9 +9,7 @@ describe Tugboat::CLI do
9
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.9.2' }).
10
10
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_sizes'))
11
11
 
12
- cli.sizes
13
-
14
- expect($stdout.string).to eq <<-eos
12
+ cli_sizes_output = <<-eos
15
13
  Sizes:
16
14
  Disk: 20GB, Memory: 512MB (slug: 512mb)
17
15
  Disk: 30GB, Memory: 1024MB (slug: 1gb)
@@ -23,6 +21,8 @@ Disk: 320GB, Memory: 32768MB (slug: 32gb)
23
21
  Disk: 480GB, Memory: 49152MB (slug: 48gb)
24
22
  Disk: 640GB, Memory: 65536MB (slug: 64gb)
25
23
  eos
24
+
25
+ expect { cli.sizes }.to output(cli_sizes_output).to_stdout
26
26
  end
27
27
  end
28
28
  end
@@ -6,6 +6,19 @@ describe Tugboat::CLI do
6
6
  let(:snapshot_name) { 'foo-snapshot' }
7
7
 
8
8
  describe 'snapshots a droplet' do
9
+ it 'without a droplet parameter' do
10
+ stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
11
+ 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' }).
12
+ to_return(status: 200, body: fixture('show_droplets'), headers: {})
13
+
14
+ snapshot_no_droplet_parameter_stdout = <<-eos
15
+ You must provide a snapshot name followed by the droplet's name.
16
+ For example: `tugboat snapshot foo-snapshot example-node.com`
17
+ eos
18
+
19
+ expect { cli.snapshot(snapshot_name) }.to raise_error(SystemExit).and output(snapshot_no_droplet_parameter_stdout).to_stdout
20
+ end
21
+
9
22
  it 'with a fuzzy name' do
10
23
  stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1').
11
24
  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' }).
@@ -20,13 +33,13 @@ describe Tugboat::CLI do
20
33
  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' }).
21
34
  to_return(status: 200, body: fixture('snapshot_response'), headers: {})
22
35
 
23
- cli.snapshot(snapshot_name, 'example3.com')
24
-
25
- expect($stdout.string).to eq <<-eos
36
+ snapshot_fuzzy_stdout = <<-eos
26
37
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
27
38
  Warning: Droplet must be in a powered off state for snapshot to be successful
28
39
  Queuing snapshot 'foo-snapshot' for 3164444 (example3.com)...Snapshot successful!
29
40
  eos
41
+
42
+ expect { cli.snapshot(snapshot_name, 'example3.com') }.to output(snapshot_fuzzy_stdout).to_stdout
30
43
  end
31
44
 
32
45
  it 'with an id' do
@@ -44,13 +57,14 @@ Queuing snapshot 'foo-snapshot' for 3164444 (example3.com)...Snapshot successful
44
57
  to_return(status: 200, body: fixture('snapshot_response'), headers: {})
45
58
 
46
59
  cli.options = cli.options.merge(id: '3164444')
47
- cli.snapshot(snapshot_name)
48
60
 
49
- expect($stdout.string).to eq <<-eos
61
+ snapshot_id_stdout = <<-eos
50
62
  Droplet id provided. Finding Droplet...done\e[0m, 3164494 (example.com)
51
63
  Warning: Droplet must be in a powered off state for snapshot to be successful
52
64
  Queuing snapshot 'foo-snapshot' for 3164494 (example.com)...Snapshot successful!
53
65
  eos
66
+
67
+ expect { cli.snapshot(snapshot_name) }.to output(snapshot_id_stdout).to_stdout
54
68
  end
55
69
 
56
70
  it 'with a name' do
@@ -68,13 +82,14 @@ Queuing snapshot 'foo-snapshot' for 3164494 (example.com)...Snapshot successful!
68
82
  to_return(status: 200, body: fixture('snapshot_response'), headers: {})
69
83
 
70
84
  cli.options = cli.options.merge(name: 'example3.com')
71
- cli.snapshot(snapshot_name)
72
85
 
73
- expect($stdout.string).to eq <<-eos
86
+ snapshot_name_stdout = <<-eos
74
87
  Droplet name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
75
88
  Warning: Droplet must be in a powered off state for snapshot to be successful
76
89
  Queuing snapshot 'foo-snapshot' for 3164444 (example3.com)...Snapshot successful!
77
90
  eos
91
+
92
+ expect { cli.snapshot(snapshot_name) }.to output(snapshot_name_stdout).to_stdout
78
93
  end
79
94
 
80
95
  it 'does not snapshot a droplet that is active' do
@@ -87,12 +102,13 @@ Queuing snapshot 'foo-snapshot' for 3164444 (example3.com)...Snapshot successful
87
102
  to_return(status: 200, body: fixture('show_droplets'), headers: {})
88
103
 
89
104
  cli.options = cli.options.merge(name: 'example.com')
90
- expect { cli.snapshot(snapshot_name) }.to raise_error(SystemExit)
91
105
 
92
- expect($stdout.string).to eq <<-eos
106
+ snapshot_active_error_stdout = <<-eos
93
107
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
94
108
  Droplet must be off for this operation to be successful.
95
109
  eos
110
+
111
+ expect { cli.snapshot(snapshot_name) }.to raise_error(SystemExit).and output(snapshot_active_error_stdout).to_stdout
96
112
  end
97
113
  end
98
114
  end
@@ -13,7 +13,7 @@ describe Tugboat::CLI do
13
13
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_droplets'))
14
14
  allow(Kernel).to receive(:exec).with('ssh', anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything, anything)
15
15
 
16
- cli.ssh('example.com')
16
+ expect { cli.ssh('example.com') }.to output(%r{Attempting SSH: baz@104.236.32.182}).to_stdout
17
17
  end
18
18
 
19
19
  it "wait's until droplet active if -w command is given and droplet already active" do
@@ -31,9 +31,7 @@ describe Tugboat::CLI do
31
31
 
32
32
  cli.options = cli.options.merge(wait: true)
33
33
 
34
- cli.ssh('example.com')
35
-
36
- expect($stdout.string).to eq <<-eos
34
+ expected_string = <<-eos
37
35
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
38
36
  Executing SSH on Droplet (example.com)...
39
37
  Wait flag given, waiting for droplet to become active
@@ -41,6 +39,8 @@ Wait flag given, waiting for droplet to become active
41
39
  Attempting SSH: baz@104.236.32.182
42
40
  SShing with options: -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i #{Dir.home}/.ssh/id_rsa2 -p 33 baz@104.236.32.182
43
41
  eos
42
+
43
+ expect { cli.ssh('example.com') }.to output(expected_string).to_stdout
44
44
  end
45
45
 
46
46
  it "wait's until droplet active if -w command is given and droplet eventually active" do
@@ -61,9 +61,7 @@ SShing with options: -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownH
61
61
 
62
62
  cli.options = cli.options.merge(wait: true)
63
63
 
64
- cli.ssh('example.com')
65
-
66
- expect($stdout.string).to eq <<-eos
64
+ expected_string = <<-eos
67
65
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
68
66
  Executing SSH on Droplet (example.com)...
69
67
  Wait flag given, waiting for droplet to become active
@@ -71,6 +69,8 @@ Wait flag given, waiting for droplet to become active
71
69
  Attempting SSH: baz@104.236.32.182
72
70
  SShing with options: -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i #{Dir.home}/.ssh/id_rsa2 -p 33 baz@104.236.32.182
73
71
  eos
72
+
73
+ expect { cli.ssh('example.com') }.to output(expected_string).to_stdout
74
74
  end
75
75
 
76
76
  it 'does not allow ssh into a droplet that is inactive' do
@@ -82,12 +82,12 @@ SShing with options: -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownH
82
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 { cli.ssh('example3.com') }.to raise_error(SystemExit)
86
-
87
- expect($stdout.string).to eq <<-eos
85
+ expected_string = <<-eos
88
86
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
89
87
  Droplet must be on for this operation to be successful.
90
88
  eos
89
+
90
+ expect { expect { cli.ssh('example3.com') }.to raise_error(SystemExit) }.to output(expected_string).to_stdout
91
91
  end
92
92
  end
93
93
  end
@@ -18,12 +18,12 @@ describe Tugboat::CLI do
18
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.9.2' }).
19
19
  to_return(status: 200, body: fixture('droplet_start_response'), headers: {})
20
20
 
21
- cli.start('example3.com')
22
-
23
- expect($stdout.string).to eq <<-eos
21
+ expected_string = <<-eos
24
22
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
25
23
  Queuing start for 3164444 (example3.com)...Start complete!
26
24
  eos
25
+
26
+ expect { cli.start('example3.com') }.to output(expected_string).to_stdout
27
27
  end
28
28
 
29
29
  it 'starts the droplet with an id' do
@@ -39,13 +39,13 @@ Queuing start for 3164444 (example3.com)...Start complete!
39
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.9.2' }).
40
40
  to_return(headers: { 'Content-Type' => 'application/json' }, status: 200, body: fixture('show_droplet_inactive'))
41
41
 
42
- cli.options = cli.options.merge(id: '3164494')
43
- cli.start
44
-
45
- expect($stdout.string).to eq <<-eos
42
+ expected_string = <<-eos
46
43
  Droplet id provided. Finding Droplet...done\e[0m, 3164494 (example.com)
47
44
  Queuing start for 3164494 (example.com)...Start complete!
48
45
  eos
46
+
47
+ cli.options = cli.options.merge(id: '3164494')
48
+ expect { cli.start }.to output(expected_string).to_stdout
49
49
  end
50
50
 
51
51
  it 'starts the droplet with a name' do
@@ -62,13 +62,13 @@ Queuing start for 3164494 (example.com)...Start complete!
62
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.9.2' }).
63
63
  to_return(status: 200, body: fixture('droplet_start_response'), headers: {})
64
64
 
65
- cli.options = cli.options.merge(name: 'example3.com')
66
- cli.start
67
-
68
- expect($stdout.string).to eq <<-eos
65
+ expected_string = <<-eos
69
66
  Droplet name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
70
67
  Queuing start for 3164444 (example3.com)...Start complete!
71
68
  eos
69
+
70
+ cli.options = cli.options.merge(name: 'example3.com')
71
+ expect { cli.start }.to output(expected_string).to_stdout
72
72
  end
73
73
 
74
74
  it 'does not start a droplet that is inactive' do
@@ -80,13 +80,13 @@ Queuing start for 3164444 (example3.com)...Start complete!
80
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.9.2' }).
81
81
  to_return(status: 200, body: fixture('show_droplets'), headers: {})
82
82
 
83
- cli.options = cli.options.merge(name: 'example.com')
84
- expect { cli.start }.to raise_error(SystemExit)
85
-
86
- expect($stdout.string).to eq <<-eos
83
+ expected_string = <<-eos
87
84
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
88
85
  Droplet must be off for this operation to be successful.
89
86
  eos
87
+
88
+ cli.options = cli.options.merge(name: 'example.com')
89
+ expect { cli.start }.to raise_error(SystemExit).and output(expected_string).to_stdout
90
90
  end
91
91
  end
92
92
  end
@@ -9,8 +9,7 @@ describe Tugboat::CLI do
9
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.9.2' }).
10
10
  to_return(status: 200, body: fixture('show_droplets'), headers: {})
11
11
 
12
- cli.verify
13
- expect($stdout.string).to eq "Authentication with DigitalOcean was successful.\n"
12
+ expect { cli.verify }.to output("Authentication with DigitalOcean was successful.\n").to_stdout
14
13
  expect(a_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1')).to have_been_made
15
14
  end
16
15
 
@@ -19,8 +18,7 @@ describe Tugboat::CLI do
19
18
  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' }).
20
19
  to_return(headers: { 'Content-Type' => 'text/html' }, status: 401, body: fixture('401'))
21
20
 
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.'
21
+ expect { cli.verify }.to raise_error(SystemExit).and output(%r{Failed to connect to DigitalOcean. Reason given from API: unauthorized - Unable to authenticate you.}).to_stdout
24
22
  expect(a_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1')).to have_been_made
25
23
  end
26
24
 
@@ -29,9 +27,8 @@ describe Tugboat::CLI do
29
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.9.2' }).
30
28
  to_return(headers: { 'Content-Type' => 'text/html' }, status: 500, body: fixture('500', 'html'))
31
29
 
32
- expect { cli.verify }.to raise_error(SystemExit)
33
- expect($stdout.string).to include 'Authentication with DigitalOcean failed at an early stage'
34
- expect($stdout.string).to include "<title>DigitalOcean - Seems we've encountered a problem!</title>"
30
+ expect { cli.verify }.to raise_error(SystemExit).and output(%r{<title>DigitalOcean - Seems we've encountered a problem!}).to_stdout
31
+
35
32
  # TODO: Make it so this doesnt barf up a huge HTML file...
36
33
  expect(a_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1')).to have_been_made
37
34
  end
@@ -6,9 +6,8 @@ describe Tugboat::CLI do
6
6
  describe 'version' do
7
7
  it 'shows the correct version' do
8
8
  cli.options = cli.options.merge(version: true)
9
- cli.version
10
9
 
11
- expect($stdout.string.chomp).to eq("Tugboat #{Tugboat::VERSION}")
10
+ expect { cli.version }.to output("Tugboat #{Tugboat::VERSION}\n").to_stdout
12
11
  end
13
12
  end
14
13
  end
@@ -17,13 +17,13 @@ describe Tugboat::CLI do
17
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.9.2' }).
18
18
  to_return(status: 200, body: fixture('show_droplet'), headers: {})
19
19
 
20
- cli.options = cli.options.merge(state: 'active')
21
- cli.wait('example.com')
22
-
23
- expect($stdout.string).to eq <<-eos
20
+ expected_string = <<-eos
24
21
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
25
22
  Waiting for droplet to become active..done\e[0m (0s)
26
23
  eos
24
+
25
+ cli.options = cli.options.merge(state: 'active')
26
+ expect { cli.wait('example.com') }.to output(expected_string).to_stdout
27
27
  end
28
28
 
29
29
  it 'loops whilst it waits for state' do
@@ -42,13 +42,13 @@ eos
42
42
  status: 200, body: fixture('show_droplet'), headers: {}
43
43
  )
44
44
 
45
- cli.options = cli.options.merge(state: 'active')
46
- cli.wait('example.com')
47
-
48
- expect($stdout.string).to eq <<-eos
45
+ expected_string = <<-eos
49
46
  Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
50
47
  Waiting for droplet to become active...done\e[0m (2s)
51
48
  eos
49
+
50
+ cli.options = cli.options.merge(state: 'active')
51
+ expect { cli.wait('example.com') }.to output(expected_string).to_stdout
52
52
  end
53
53
 
54
54
  it 'waits for a droplet with an id' do
@@ -60,13 +60,13 @@ eos
60
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.9.2' }).
61
61
  to_return(status: 200, body: fixture('show_droplet'), headers: {})
62
62
 
63
- cli.options = cli.options.merge(id: '6918990', state: 'active')
64
- cli.wait
65
-
66
- expect($stdout.string).to eq <<-eos
63
+ expected_string = <<-eos
67
64
  Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
68
65
  Waiting for droplet to become active..done\e[0m (0s)
69
66
  eos
67
+
68
+ cli.options = cli.options.merge(id: '6918990', state: 'active')
69
+ expect { cli.wait }.to output(expected_string).to_stdout
70
70
  end
71
71
 
72
72
  it 'waits for a droplet with a name' do
@@ -82,13 +82,13 @@ Waiting for droplet to become active..done\e[0m (0s)
82
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.9.2' }).
83
83
  to_return(status: 200, body: fixture('show_droplet'), headers: {})
84
84
 
85
- cli.options = cli.options.merge(name: 'example.com', state: 'active')
86
- cli.wait
87
-
88
- expect($stdout.string).to eq <<-eos
85
+ expected_string = <<-eos
89
86
  Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
90
87
  Waiting for droplet to become active..done\e[0m (0s)
91
88
  eos
89
+
90
+ cli.options = cli.options.merge(name: 'example.com', state: 'active')
91
+ expect { cli.wait }.to output(expected_string).to_stdout
92
92
  end
93
93
  end
94
94
  end
data/spec/config_spec.rb CHANGED
@@ -34,12 +34,13 @@ describe Tugboat::Configuration do
34
34
  let(:private_networking) { 'false' }
35
35
  let(:backups_enabled) { 'false' }
36
36
  let(:ip6) { 'false' }
37
+ let(:timeout) { '30' }
37
38
 
38
39
  let(:config) { described_class.instance }
39
40
 
40
41
  before do
41
42
  # Create a temporary file
42
- config.create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key_id, private_networking, backups_enabled, ip6)
43
+ config.create_config_file(access_token, ssh_key_path, ssh_user, ssh_port, region, image, size, ssh_key_id, private_networking, backups_enabled, ip6, timeout)
43
44
  end
44
45
 
45
46
  it 'can be created' do
@@ -91,6 +92,11 @@ describe Tugboat::Configuration do
91
92
  backups_enabled = data['defaults']
92
93
  expect(backups_enabled).to have_key('backups_enabled')
93
94
  end
95
+
96
+ it 'has timeout set' do
97
+ timeout_set = data['connection']
98
+ expect(timeout_set).to have_key('timeout')
99
+ end
94
100
  end
95
101
  describe 'backwards compatible' do
96
102
  let(:client_key) { 'foo' }