tugboat 0.2.0 → 1.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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +5 -4
  4. data/CHANGELOG.md +325 -102
  5. data/CHANGELOG_old.md +150 -0
  6. data/Gemfile +6 -0
  7. data/README.md +12 -6
  8. data/Rakefile +7 -3
  9. data/features/step_definitions/steps.rb +0 -0
  10. data/features/support/env.rb +9 -0
  11. data/features/vagrant-adam/config_current_directory.feature +27 -0
  12. data/lib/tugboat/cli.rb +31 -3
  13. data/lib/tugboat/config.rb +13 -5
  14. data/lib/tugboat/middleware.rb +8 -0
  15. data/lib/tugboat/middleware/ask_for_credentials.rb +5 -4
  16. data/lib/tugboat/middleware/authentication_middleware.rb +2 -2
  17. data/lib/tugboat/middleware/config.rb +29 -0
  18. data/lib/tugboat/middleware/custom_logger.rb +2 -2
  19. data/lib/tugboat/middleware/find_droplet.rb +4 -0
  20. data/lib/tugboat/middleware/info_droplet.rb +5 -0
  21. data/lib/tugboat/middleware/inject_client.rb +1 -1
  22. data/lib/tugboat/middleware/list_droplets.rb +5 -1
  23. data/lib/tugboat/middleware/list_regions.rb +2 -2
  24. data/lib/tugboat/middleware/ssh_droplet.rb +17 -2
  25. data/lib/tugboat/version.rb +1 -1
  26. data/spec/cli/add_key_spec.rb +9 -9
  27. data/spec/cli/authorize_cli_spec.rb +76 -52
  28. data/spec/cli/create_cli_spec.rb +39 -4
  29. data/spec/cli/debug_cli_spec.rb +44 -0
  30. data/spec/cli/destroy_cli_spec.rb +30 -11
  31. data/spec/cli/destroy_image_cli_spec.rb +11 -11
  32. data/spec/cli/droplets_cli_spec.rb +6 -6
  33. data/spec/cli/halt_cli_spec.rb +9 -9
  34. data/spec/cli/images_cli_spec.rb +6 -6
  35. data/spec/cli/info_cli_spec.rb +42 -7
  36. data/spec/cli/info_image_cli_spec.rb +6 -6
  37. data/spec/cli/keys_cli_spec.rb +1 -1
  38. data/spec/cli/password_reset_cli_spec.rb +8 -8
  39. data/spec/cli/rebuild_cli_spec.rb +49 -49
  40. data/spec/cli/regions_cli_spec.rb +4 -4
  41. data/spec/cli/resize_cli_spec.rb +8 -8
  42. data/spec/cli/restart_cli_spec.rb +8 -8
  43. data/spec/cli/sizes_cli_spec.rb +1 -1
  44. data/spec/cli/snapshot_cli_spec.rb +7 -7
  45. data/spec/cli/ssh_cli_spec.rb +4 -4
  46. data/spec/cli/start_cli_spec.rb +7 -7
  47. data/spec/cli/verify_cli_spec.rb +10 -2
  48. data/spec/cli/wait_cli_spec.rb +6 -6
  49. data/spec/fixtures/500.html +68 -0
  50. data/spec/fixtures/show_droplet.json +1 -0
  51. data/spec/fixtures/show_droplet_fuzzy.json +13 -0
  52. data/spec/fixtures/show_droplet_inactive.json +1 -0
  53. data/spec/fixtures/show_droplets.json +2 -0
  54. data/spec/fixtures/show_droplets_fuzzy.json +35 -0
  55. data/spec/fixtures/show_droplets_inactive.json +2 -0
  56. data/spec/fixtures/show_regions.json +9 -6
  57. data/spec/middleware/base_spec.rb +1 -1
  58. data/spec/middleware/check_credentials_spec.rb +1 -1
  59. data/spec/middleware/inject_client_spec.rb +29 -0
  60. data/spec/middleware/inject_configuration_spec.rb +1 -1
  61. data/spec/middleware/ssh_droplet_spec.rb +30 -7
  62. data/spec/shared/environment.rb +1 -0
  63. data/spec/spec_helper.rb +11 -4
  64. data/tugboat.gemspec +9 -7
  65. metadata +64 -33
@@ -6,12 +6,12 @@ describe Tugboat::CLI do
6
6
  describe "destroy" do
7
7
  it "destroys a droplet with a fuzzy name" do
8
8
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:status => 200, :body => fixture("show_droplets"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
10
10
 
11
11
  stub_request(:delete, "https://api.digitalocean.com/droplets/100823/destroy?api_key=#{api_key}&client_id=#{client_key}").
12
- to_return(:status => 200, :body => fixture("show_droplet"))
12
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
13
13
 
14
- $stdin.should_receive(:gets).and_return("y")
14
+ expect($stdin).to receive(:gets).and_return("y")
15
15
 
16
16
  @cli.destroy("foo")
17
17
 
@@ -25,12 +25,12 @@ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 100823 (foo)\nWarni
25
25
 
26
26
  it "destroys a droplet with an id" do
27
27
  stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
28
- to_return(:status => 200, :body => fixture("show_droplet"))
28
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
29
29
 
30
30
  stub_request(:delete, "https://api.digitalocean.com/droplets/100823/destroy?api_key=#{api_key}&client_id=#{client_key}").
31
- to_return(:status => 200, :body => fixture("show_droplet"))
31
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
32
32
 
33
- $stdin.should_receive(:gets).and_return("y")
33
+ expect($stdin).to receive(:gets).and_return("y")
34
34
 
35
35
  @cli.options = @cli.options.merge(:id => droplet_id)
36
36
  @cli.destroy
@@ -46,12 +46,12 @@ Droplet id provided. Finding Droplet...done\e[0m, 100823 (foo)\nWarning! Potenti
46
46
 
47
47
  it "destroys a droplet with a name" do
48
48
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
49
- to_return(:status => 200, :body => fixture("show_droplets"))
49
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
50
50
 
51
51
  stub_request(:delete, "https://api.digitalocean.com/droplets/100823/destroy?api_key=#{api_key}&client_id=#{client_key}").
52
- to_return(:status => 200, :body => fixture("show_droplet"))
52
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
53
53
 
54
- $stdin.should_receive(:gets).and_return("y")
54
+ expect($stdin).to receive(:gets).and_return("y")
55
55
 
56
56
  @cli.options = @cli.options.merge(:name => droplet_name)
57
57
  @cli.destroy
@@ -67,10 +67,10 @@ Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)\nWarning! Po
67
67
 
68
68
  it "destroys a droplet with confirm flag set" do
69
69
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
70
- to_return(:status => 200, :body => fixture("show_droplets"))
70
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
71
71
 
72
72
  stub_request(:delete, "https://api.digitalocean.com/droplets/100823/destroy?api_key=#{api_key}&client_id=#{client_key}").
73
- to_return(:status => 200, :body => fixture("show_droplet"))
73
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
74
74
 
75
75
  @cli.options = @cli.options.merge(:name => droplet_name)
76
76
  @cli.options = @cli.options.merge(:confirm => true)
@@ -84,6 +84,25 @@ Queuing destroy for 100823 (foo)...done
84
84
  expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
85
85
  expect(a_request(:delete, "https://api.digitalocean.com/droplets/100823/destroy?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
86
86
  end
87
+
88
+ it "does not destroy a droplet if no is chosen" do
89
+ stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
90
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
91
+
92
+ stub_request(:delete, "https://api.digitalocean.com/droplets/100823/destroy?api_key=#{api_key}&client_id=#{client_key}").
93
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
94
+
95
+ $stdin.should_receive(:gets).and_return("n")
96
+
97
+ expect {@cli.destroy("foo")}.to raise_error(SystemExit)
98
+
99
+ expect($stdout.string).to eq <<-eos
100
+ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 100823 (foo)\nWarning! Potentially destructive action. Please confirm [y/n]: Aborted due to user request.
101
+ eos
102
+
103
+ expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
104
+ expect(a_request(:delete, "https://api.digitalocean.com/droplets/100823/destroy?api_key=#{api_key}&client_id=#{client_key}")).to_not have_been_made
105
+ end
87
106
  end
88
107
 
89
108
  end
@@ -6,12 +6,12 @@ describe Tugboat::CLI do
6
6
  describe "destroy image" do
7
7
  it "destroys an image with a fuzzy name" do
8
8
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:status => 200, :body => fixture("show_images"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
10
10
 
11
11
  stub_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}").
12
- to_return(:status => 200, :body => fixture("show_image"))
12
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
13
13
 
14
- $stdin.should_receive(:gets).and_return("y")
14
+ expect($stdin).to receive(:gets).and_return("y")
15
15
 
16
16
  @cli.destroy_image("NLP Final")
17
17
 
@@ -25,12 +25,12 @@ Image fuzzy name provided. Finding image ID...done\e[0m, 478 (NLP Final)\nWarnin
25
25
 
26
26
  it "destroys an image with an id" do
27
27
  stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
28
- to_return(:status => 200, :body => fixture("show_image"))
28
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
29
29
 
30
30
  stub_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}").
31
- to_return(:status => 200, :body => fixture("show_image"))
31
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
32
32
 
33
- $stdin.should_receive(:gets).and_return("y")
33
+ expect($stdin).to receive(:gets).and_return("y")
34
34
 
35
35
  @cli.options = @cli.options.merge(:id => 478)
36
36
  @cli.destroy_image
@@ -46,12 +46,12 @@ Image id provided. Finding Image...done\e[0m, 478 (NLP Final)\nWarning! Potentia
46
46
 
47
47
  it "destroys an image with a name" do
48
48
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}").
49
- to_return(:status => 200, :body => fixture("show_images"))
49
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
50
50
 
51
51
  stub_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}").
52
- to_return(:status => 200, :body => fixture("show_image"))
52
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
53
53
 
54
- $stdin.should_receive(:gets).and_return("y")
54
+ expect($stdin).to receive(:gets).and_return("y")
55
55
 
56
56
  @cli.options = @cli.options.merge(:name => "NLP Final")
57
57
  @cli.destroy_image
@@ -67,10 +67,10 @@ Image name provided. Finding image ID...done\e[0m, 478 (NLP Final)\nWarning! Pot
67
67
 
68
68
  it "destroys an image with confirm flag set" do
69
69
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}").
70
- to_return(:status => 200, :body => fixture("show_images"))
70
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
71
71
 
72
72
  stub_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}").
73
- to_return(:status => 200, :body => fixture("show_image"))
73
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
74
74
 
75
75
  @cli.options = @cli.options.merge(:name => "NLP Final")
76
76
  @cli.options = @cli.options.merge(:confirm => true)
@@ -6,22 +6,22 @@ describe Tugboat::CLI do
6
6
  describe "droplets" do
7
7
  it "shows a list when droplets exist" do
8
8
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:status => 200, :body => fixture("show_droplets"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
10
10
 
11
11
  @cli.droplets
12
12
 
13
13
  expect($stdout.string).to eq <<-eos
14
- test222 (ip: 33.33.33.10, status: \e[32mactive\e[0m, region: 1, id: 100823)
14
+ test222 (ip: 33.33.33.10, privateip: 10.20.30.1, status: \e[32mactive\e[0m, region: 1, id: 100823)
15
15
  test223 (ip: 33.33.33.10, status: \e[32mactive\e[0m, region: 1, id: 100823)
16
- foo (ip: 33.33.33.10, status: \e[32mactive\e[0m, region: 1, id: 100823)
16
+ foo (ip: 33.33.33.10, privateip: 10.20.30.40, status: \e[32mactive\e[0m, region: 1, id: 100823)
17
17
  eos
18
18
 
19
19
  expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
20
20
  end
21
21
 
22
- it "returns an error when no droplets exist" do
22
+ it "returns an error message when no droplets exist" do
23
23
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
24
- to_return(:status => 200, :body => fixture("show_droplets_empty"))
24
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets_empty"))
25
25
 
26
26
  @cli.droplets
27
27
 
@@ -34,7 +34,7 @@ Try creating one with \e[32m`tugboat create`\e[0m
34
34
  end
35
35
  it "shows no output when --quiet is set" do
36
36
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
37
- to_return(:status => 200, :body => fixture("show_droplets_empty"))
37
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets_empty"))
38
38
 
39
39
  @cli.options = @cli.options.merge(:quiet => true)
40
40
  @cli.droplets
@@ -6,10 +6,10 @@ describe Tugboat::CLI do
6
6
  describe "halt" do
7
7
  it "halts a droplet with a fuzzy name" do
8
8
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:status => 200, :body => fixture("show_droplets"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
10
10
 
11
11
  stub_request(:put, "https://api.digitalocean.com/droplets/100823/shutdown?api_key=#{api_key}&client_id=#{client_key}").
12
- to_return(:status => 200, :body => fixture("show_droplet"))
12
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
13
13
 
14
14
  @cli.halt("foo")
15
15
 
@@ -24,9 +24,9 @@ Queuing shutdown for 100823 (foo)...done
24
24
 
25
25
  it "halts a droplet hard when the hard option is used" do
26
26
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
27
- to_return(:status => 200, :body => fixture("show_droplets"))
27
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
28
28
  stub_request(:put, "https://api.digitalocean.com/droplets/100823/power_off?api_key=#{api_key}&client_id=#{client_key}").
29
- to_return(:status => 200, :body => fixture("show_droplet"))
29
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
30
30
 
31
31
  @cli.options = @cli.options.merge(:hard => true)
32
32
  @cli.halt("foo")
@@ -42,10 +42,10 @@ Queuing hard shutdown for 100823 (foo)...done
42
42
 
43
43
  it "halts a droplet with an id" do
44
44
  stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
45
- to_return(:status => 200, :body => fixture("show_droplet"))
45
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
46
46
 
47
47
  stub_request(:put, "https://api.digitalocean.com/droplets/100823/shutdown?api_key=#{api_key}&client_id=#{client_key}").
48
- to_return(:status => 200, :body => fixture("show_droplet"))
48
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
49
49
 
50
50
  @cli.options = @cli.options.merge(:id => droplet_id)
51
51
  @cli.halt
@@ -62,10 +62,10 @@ Queuing shutdown for 100823 (foo)...done
62
62
 
63
63
  it "halts a droplet with a name" do
64
64
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
65
- to_return(:status => 200, :body => fixture("show_droplets"))
65
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
66
66
 
67
67
  stub_request(:put, "https://api.digitalocean.com/droplets/100823/shutdown?api_key=#{api_key}&client_id=#{client_key}").
68
- to_return(:status => 200, :body => fixture("show_droplet"))
68
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
69
69
 
70
70
  @cli.options = @cli.options.merge(:name => droplet_name)
71
71
  @cli.halt
@@ -82,7 +82,7 @@ Queuing shutdown for 100823 (foo)...done
82
82
 
83
83
  it "does not halt a droplet that is off" do
84
84
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
85
- to_return(:status => 200, :body => fixture("show_droplets_inactive"))
85
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets_inactive"))
86
86
 
87
87
  @cli.options = @cli.options.merge(:name => droplet_name)
88
88
  expect {@cli.halt}.to raise_error(SystemExit)
@@ -6,7 +6,7 @@ describe Tugboat::CLI do
6
6
  describe "images" do
7
7
  it "shows a list" do
8
8
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}&filter=my_images").
9
- to_return(:status => 200, :body => fixture("show_images"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
10
10
 
11
11
  @cli.images
12
12
 
@@ -21,7 +21,7 @@ NLP Final (id: 478, distro: Ubuntu)
21
21
 
22
22
  it "acknowledges when my images are empty" do
23
23
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}&filter=my_images").
24
- to_return(:status => 200, :body => fixture("show_images_empty"))
24
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images_empty"))
25
25
 
26
26
  @cli.images
27
27
 
@@ -35,10 +35,10 @@ No images found
35
35
 
36
36
  it "acknowledges when my images are empty and also shows a global list" do
37
37
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}&filter=my_images").
38
- to_return(:status => 200, :body => fixture("show_images_empty"))
38
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images_empty"))
39
39
 
40
40
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}&filter=global").
41
- to_return(:status => 200, :body => fixture("show_images_global"))
41
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images_global"))
42
42
 
43
43
  @cli.options = @cli.options.merge(:global => true)
44
44
  @cli.images
@@ -59,10 +59,10 @@ Global Final (id: 479, distro: Ubuntu)
59
59
 
60
60
  it "shows a global list" do
61
61
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}&filter=my_images").
62
- to_return(:status => 200, :body => fixture("show_images"))
62
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
63
63
 
64
64
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}&filter=global").
65
- to_return(:status => 200, :body => fixture("show_images_global"))
65
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images_global"))
66
66
 
67
67
  @cli.options = @cli.options.merge(:global => true)
68
68
  @cli.images
@@ -6,10 +6,10 @@ describe Tugboat::CLI do
6
6
  describe "show" do
7
7
  it "shows a droplet with a fuzzy name" do
8
8
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:status => 200, :body => fixture("show_droplets"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
10
10
 
11
11
  stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
12
- to_return(:status => 200, :body => fixture("show_droplet"))
12
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
13
13
 
14
14
  @cli.info("foo")
15
15
 
@@ -20,6 +20,7 @@ Name: foo
20
20
  ID: 100823
21
21
  Status: \e[32mactive\e[0m
22
22
  IP: 33.33.33.10
23
+ Private IP: 10.20.30.40
23
24
  Region ID: 1
24
25
  Image ID: 420
25
26
  Size ID: 33
@@ -32,10 +33,10 @@ Backups Active: false
32
33
 
33
34
  it "shows a droplet with an id" do
34
35
  stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
35
- to_return(:status => 200, :body => fixture("show_droplet"))
36
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
36
37
 
37
38
  stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
38
- to_return(:status => 200, :body => fixture("show_droplet"))
39
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
39
40
 
40
41
  @cli.options = @cli.options.merge(:id => droplet_id)
41
42
  @cli.info
@@ -47,6 +48,7 @@ Name: foo
47
48
  ID: 100823
48
49
  Status: \e[32mactive\e[0m
49
50
  IP: 33.33.33.10
51
+ Private IP: 10.20.30.40
50
52
  Region ID: 1
51
53
  Image ID: 420
52
54
  Size ID: 33
@@ -59,10 +61,10 @@ Backups Active: false
59
61
 
60
62
  it "shows a droplet with a name" do
61
63
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
62
- to_return(:status => 200, :body => fixture("show_droplets"))
64
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
63
65
 
64
66
  stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
65
- to_return(:status => 200, :body => fixture("show_droplet"))
67
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
66
68
 
67
69
  @cli.options = @cli.options.merge(:name => droplet_name)
68
70
  @cli.info
@@ -74,6 +76,7 @@ Name: foo
74
76
  ID: 100823
75
77
  Status: \e[32mactive\e[0m
76
78
  IP: 33.33.33.10
79
+ Private IP: 10.20.30.40
77
80
  Region ID: 1
78
81
  Image ID: 420
79
82
  Size ID: 33
@@ -84,6 +87,38 @@ Backups Active: false
84
87
  expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
85
88
  end
86
89
 
90
+ it "allows choice of multiple droplets" do
91
+ stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
92
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets_fuzzy"))
93
+
94
+ stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
95
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet_fuzzy"))
96
+
97
+ $stdin.should_receive(:gets).and_return('0')
98
+
99
+ @cli.info("test")
100
+
101
+ expect($stdout.string).to eq <<-eos
102
+ Droplet fuzzy name provided. Finding droplet ID...Multiple droplets found.
103
+
104
+ 0) test222 (100823)
105
+ 1) test223 (100824)
106
+
107
+ Please choose a droplet: ["0", "1"]
108
+ Name: test222
109
+ ID: 100823
110
+ Status: \e[32mactive\e[0m
111
+ IP: 33.33.33.10
112
+ Region ID: 1
113
+ Image ID: 420
114
+ Size ID: 33
115
+ Backups Active: false
116
+ eos
117
+
118
+ expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
119
+ expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
120
+ end
121
+
87
122
  end
88
123
 
89
- end
124
+ end
@@ -6,10 +6,10 @@ describe Tugboat::CLI do
6
6
  describe "show" do
7
7
  it "shows an image with a fuzzy name" do
8
8
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:status => 200, :body => fixture("show_images"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
10
10
 
11
11
  stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
12
- to_return(:status => 200, :body => fixture("show_image"))
12
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
13
13
 
14
14
  @cli.info_image("NLP Final")
15
15
 
@@ -23,10 +23,10 @@ Image fuzzy name provided. Finding image ID...done\e[0m, 478 (NLP Final)\n\nName
23
23
 
24
24
  it "shows an image with an id" do
25
25
  stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
26
- to_return(:status => 200, :body => fixture("show_image"))
26
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
27
27
 
28
28
  stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
29
- to_return(:status => 200, :body => fixture("show_image"))
29
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
30
30
 
31
31
  @cli.options = @cli.options.merge(:id => 478)
32
32
  @cli.info_image
@@ -40,10 +40,10 @@ Image id provided. Finding Image...done\e[0m, 478 (NLP Final)\n\nName:
40
40
 
41
41
  it "shows an image with a name" do
42
42
  stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}").
43
- to_return(:status => 200, :body => fixture("show_images"))
43
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
44
44
 
45
45
  stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
46
- to_return(:status => 200, :body => fixture("show_image"))
46
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
47
47
 
48
48
  @cli.options = @cli.options.merge(:name => "NLP Final")
49
49
  @cli.info_image
@@ -6,7 +6,7 @@ describe Tugboat::CLI do
6
6
  describe "keys" do
7
7
  it "shows a list" do
8
8
  stub_request(:get, "https://api.digitalocean.com/ssh_keys?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:status => 200, :body => fixture("show_keys"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_keys"))
10
10
 
11
11
  @cli.keys
12
12
 
@@ -6,9 +6,9 @@ describe Tugboat::CLI do
6
6
  describe "passwordreset" do
7
7
  it "resets the root password given a fuzzy name" do
8
8
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:status => 200, :body => fixture("show_droplets"))
9
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
10
10
  stub_request(:post, "https://api.digitalocean.com/droplets/100823/password_reset?api_key=#{api_key}&client_id=#{client_key}").
11
- to_return(:status => 200, :body => '{"status":"OK","event_id":456}')
11
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => '{"status":"OK","event_id":456}')
12
12
 
13
13
  @cli.password_reset("foo")
14
14
 
@@ -26,9 +26,9 @@ Your new root password will be emailed to you
26
26
 
27
27
  it "resets the root password given an id" do
28
28
  stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
29
- to_return(:status => 200, :body => fixture("show_droplet"))
29
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
30
30
  stub_request(:post, "https://api.digitalocean.com/droplets/100823/password_reset?api_key=#{api_key}&client_id=#{client_key}").
31
- to_return(:status => 200, :body => '{"status":"OK","event_id":456}')
31
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => '{"status":"OK","event_id":456}')
32
32
 
33
33
  @cli.options = @cli.options.merge(:id => 100823)
34
34
  @cli.password_reset
@@ -47,9 +47,9 @@ Your new root password will be emailed to you
47
47
 
48
48
  it "resets the root password given a name" do
49
49
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
50
- to_return(:status => 200, :body => fixture("show_droplets"))
50
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
51
51
  stub_request(:post, "https://api.digitalocean.com/droplets/100823/password_reset?api_key=#{api_key}&client_id=#{client_key}").
52
- to_return(:status => 200, :body => '{"status":"OK","event_id":456}')
52
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => '{"status":"OK","event_id":456}')
53
53
 
54
54
  @cli.options = @cli.options.merge(:name => "foo")
55
55
  @cli.password_reset
@@ -68,9 +68,9 @@ Your new root password will be emailed to you
68
68
 
69
69
  it "raises SystemExit when a request fails" do
70
70
  stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
71
- to_return(:status => 200, :body => fixture("show_droplets"))
71
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
72
72
  stub_request(:post, "https://api.digitalocean.com/droplets/100823/password_reset?api_key=#{api_key}&client_id=#{client_key}").
73
- to_return(:status => 500, :body => '{"status":"ERROR","message":"Some error"}')
73
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 500, :body => '{"status":"ERROR","message":"Some error"}')
74
74
 
75
75
  expect { @cli.password_reset("foo") }.to raise_error(SystemExit)
76
76