tugboat 1.3.1 → 2.0.0.RC1

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +12 -8
  4. data/lib/tugboat/cli.rb +8 -7
  5. data/lib/tugboat/config.rb +8 -12
  6. data/lib/tugboat/middleware/add_key.rb +9 -6
  7. data/lib/tugboat/middleware/ask_for_credentials.rb +7 -8
  8. data/lib/tugboat/middleware/check_configuration.rb +1 -1
  9. data/lib/tugboat/middleware/check_credentials.rb +4 -2
  10. data/lib/tugboat/middleware/config.rb +3 -4
  11. data/lib/tugboat/middleware/create_droplet.rb +32 -26
  12. data/lib/tugboat/middleware/destroy_droplet.rb +6 -6
  13. data/lib/tugboat/middleware/destroy_image.rb +6 -6
  14. data/lib/tugboat/middleware/find_droplet.rb +20 -16
  15. data/lib/tugboat/middleware/find_image.rb +17 -10
  16. data/lib/tugboat/middleware/halt_droplet.rb +8 -8
  17. data/lib/tugboat/middleware/info_droplet.rb +38 -25
  18. data/lib/tugboat/middleware/info_image.rb +5 -5
  19. data/lib/tugboat/middleware/inject_client.rb +3 -9
  20. data/lib/tugboat/middleware/list_droplets.rb +6 -4
  21. data/lib/tugboat/middleware/list_images.rb +28 -23
  22. data/lib/tugboat/middleware/list_regions.rb +3 -3
  23. data/lib/tugboat/middleware/list_sizes.rb +3 -3
  24. data/lib/tugboat/middleware/list_ssh_keys.rb +5 -4
  25. data/lib/tugboat/middleware/password_reset.rb +7 -7
  26. data/lib/tugboat/middleware/rebuild_droplet.rb +8 -8
  27. data/lib/tugboat/middleware/resize_droplet.rb +7 -7
  28. data/lib/tugboat/middleware/restart_droplet.rb +8 -8
  29. data/lib/tugboat/middleware/snapshot_droplet.rb +6 -6
  30. data/lib/tugboat/middleware/ssh_droplet.rb +3 -1
  31. data/lib/tugboat/middleware/start_droplet.rb +6 -6
  32. data/lib/tugboat/middleware/wait_for_state.rb +6 -6
  33. data/lib/tugboat/version.rb +1 -1
  34. data/spec/cli/add_key_spec.rb +16 -9
  35. data/spec/cli/authorize_cli_spec.rb +24 -29
  36. data/spec/cli/config_cli_spec.rb +57 -0
  37. data/spec/cli/create_cli_spec.rb +18 -28
  38. data/spec/cli/debug_cli_spec.rb +8 -14
  39. data/spec/cli/destroy_cli_spec.rb +39 -50
  40. data/spec/cli/destroy_image_cli_spec.rb +33 -39
  41. data/spec/cli/droplets_cli_spec.rb +15 -12
  42. data/spec/cli/halt_cli_spec.rb +50 -46
  43. data/spec/cli/images_cli_spec.rb +134 -58
  44. data/spec/cli/info_cli_spec.rb +139 -139
  45. data/spec/cli/info_image_cli_spec.rb +113 -26
  46. data/spec/cli/keys_cli_spec.rb +7 -5
  47. data/spec/cli/password_reset_cli_spec.rb +46 -44
  48. data/spec/cli/rebuild_cli_spec.rb +187 -101
  49. data/spec/cli/regions_cli_spec.rb +13 -6
  50. data/spec/cli/resize_cli_spec.rb +51 -48
  51. data/spec/cli/restart_cli_spec.rb +41 -39
  52. data/spec/cli/sizes_cli_spec.rb +13 -8
  53. data/spec/cli/snapshot_cli_spec.rb +36 -37
  54. data/spec/cli/ssh_cli_spec.rb +7 -15
  55. data/spec/cli/start_cli_spec.rb +39 -35
  56. data/spec/cli/verify_cli_spec.rb +20 -12
  57. data/spec/cli/wait_cli_spec.rb +43 -27
  58. data/spec/config_spec.rb +19 -25
  59. data/spec/fixtures/create_droplet.json +44 -0
  60. data/spec/fixtures/create_ssh_key.json +4 -4
  61. data/spec/fixtures/create_ssh_key_from_file.json +8 -0
  62. data/spec/fixtures/droplet_start_response.json +13 -0
  63. data/spec/fixtures/not_found.json +4 -0
  64. data/spec/fixtures/password_reset_response.json +13 -0
  65. data/spec/fixtures/power_cycle_response.json +13 -0
  66. data/spec/fixtures/resize_droplet.json +13 -0
  67. data/spec/fixtures/restart_response.json +13 -0
  68. data/spec/fixtures/show_coreos_image.json +23 -0
  69. data/spec/fixtures/show_droplet.json +90 -11
  70. data/spec/fixtures/show_droplet_inactive.json +90 -11
  71. data/spec/fixtures/show_droplets.json +249 -30
  72. data/spec/fixtures/show_droplets_empty.json +5 -2
  73. data/spec/fixtures/show_image.json +14 -7
  74. data/spec/fixtures/show_images.json +1075 -13
  75. data/spec/fixtures/show_images_global.json +25 -16
  76. data/spec/fixtures/show_keys.json +15 -7
  77. data/spec/fixtures/show_redmine_image.json +24 -0
  78. data/spec/fixtures/show_regions.json +181 -12
  79. data/spec/fixtures/show_sizes.json +178 -9
  80. data/spec/fixtures/shutdown_response.json +13 -0
  81. data/spec/fixtures/snapshot_response.json +13 -0
  82. data/spec/fixtures/ubuntu_image_9801951.json +24 -0
  83. data/spec/middleware/check_credentials_spec.rb +4 -3
  84. data/spec/middleware/inject_client_spec.rb +2 -2
  85. data/spec/shared/environment.rb +6 -7
  86. data/spec/spec_helper.rb +1 -1
  87. data/tugboat.gemspec +39 -19
  88. metadata +50 -14
  89. data/spec/fixtures/show_droplet_fuzzy.json +0 -13
  90. data/spec/fixtures/show_droplets_fuzzy.json +0 -35
  91. data/spec/fixtures/show_droplets_inactive.json +0 -37
@@ -5,19 +5,26 @@ describe Tugboat::CLI do
5
5
 
6
6
  describe "regions" do
7
7
  it "shows a list" do
8
- stub_request(:get, "https://api.digitalocean.com/regions?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_regions"))
8
+ stub_request(:get, "https://api.digitalocean.com/v2/regions?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.9.2'}).
10
+ to_return(:status => 200, :body => fixture("show_regions"), :headers => {'Content-Type' => 'application/json'},)
10
11
 
11
12
  @cli.regions
12
13
 
13
14
  expect($stdout.string).to eq <<-eos
14
15
  Regions:
15
- Region 1 (id: 1) (slug: reg1)
16
- Region 2 (id: 2) (slug: reg2)
17
- Region 3 (id: 3) (slug: reg3)
16
+ Amsterdam 1 (slug: ams1)
17
+ Amsterdam 2 (slug: ams2)
18
+ Amsterdam 3 (slug: ams3)
19
+ London 1 (slug: lon1)
20
+ New York 1 (slug: nyc1)
21
+ New York 2 (slug: nyc2)
22
+ New York 3 (slug: nyc3)
23
+ San Francisco 1 (slug: sfo1)
24
+ Singapore 1 (slug: sgp1)
18
25
  eos
19
26
 
20
- expect(a_request(:get, "https://api.digitalocean.com/regions?api_key=#{api_key}&client_id=#{client_key}")).
27
+ expect(a_request(:get, "https://api.digitalocean.com/v2/regions?per_page=200")).
21
28
  to have_been_made
22
29
  end
23
30
  end
@@ -5,78 +5,81 @@ describe Tugboat::CLI do
5
5
 
6
6
  describe "resize" do
7
7
  it "resizes a droplet with a fuzzy name" do
8
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
10
- stub_request(:get, "https://api.digitalocean.com/droplets/100823/resize?api_key=#{api_key}&client_id=#{client_key}&size_id=123").
11
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => '{"status":"OK","event_id":456}')
8
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?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.9.2'}).
10
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
12
11
 
13
- @cli.options = @cli.options.merge(:size => 123)
14
- @cli.resize("foo")
12
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/6918990/actions").
13
+ with(:body => "{\"type\":\"resize\",\"size\":\"1gb\"}",
14
+ :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'}).
15
+ to_return(:status => 200, :body => fixture('resize_droplet'), :headers => {})
16
+
17
+ @cli.options = @cli.options.merge(:size => '1gb')
18
+ @cli.resize("example.com")
15
19
 
16
20
  expect($stdout.string).to eq <<-eos
17
- Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 100823 (foo)
18
- Queuing resize for 100823 (foo)...done
21
+ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
22
+ Queuing resize for 6918990 (example.com)...Resize complete!
19
23
  eos
20
-
21
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).
22
- to have_been_made
23
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823/resize?api_key=#{api_key}&client_id=#{client_key}&size_id=123")).
24
- to have_been_made
25
24
  end
26
25
 
27
26
  it "resizes a droplet with an id" do
28
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
29
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
30
- stub_request(:get, "https://api.digitalocean.com/droplets/100823/resize?api_key=#{api_key}&client_id=#{client_key}&size_id=123").
31
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => '{"status":"OK","event_id":456}')
27
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
28
+ 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'}).
29
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
30
+
31
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/6918990/actions").
32
+ with(:body => "{\"type\":\"resize\",\"size\":\"1gb\"}",
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'}).
34
+ to_return(:status => 200, :body => fixture('resize_droplet'), :headers => {})
32
35
 
33
- @cli.options = @cli.options.merge(:size => 123, :id => 100823)
36
+ @cli.options = @cli.options.merge(:size => '1gb', :id => 6918990)
34
37
  @cli.resize
35
38
 
36
39
  expect($stdout.string).to eq <<-eos
37
- Droplet id provided. Finding Droplet...done\e[0m, 100823 (foo)
38
- Queuing resize for 100823 (foo)...done
40
+ Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
41
+ Queuing resize for 6918990 (example.com)...Resize complete!
39
42
  eos
40
-
41
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).
42
- to have_been_made
43
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823/resize?api_key=#{api_key}&client_id=#{client_key}&size_id=123")).
44
- to have_been_made
45
43
  end
46
44
 
47
45
  it "resizes a droplet with a name" do
48
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
49
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
50
- stub_request(:get, "https://api.digitalocean.com/droplets/100823/resize?api_key=#{api_key}&client_id=#{client_key}&size_id=123").
51
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => '{"status":"OK","event_id":456}')
46
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
47
+ 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'}).
48
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
49
+
50
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/6918990/actions").
51
+ with(:body => "{\"type\":\"resize\",\"size\":\"1gb\"}",
52
+ :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'}).
53
+ to_return(:status => 200, :body => fixture('resize_droplet'), :headers => {})
52
54
 
53
- @cli.options = @cli.options.merge(:size => 123, :name => "foo")
55
+ @cli.options = @cli.options.merge(:size => '1gb', :name => "example.com")
54
56
  @cli.resize
55
57
 
56
58
  expect($stdout.string).to eq <<-eos
57
- Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)
58
- Queuing resize for 100823 (foo)...done
59
+ Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
60
+ Queuing resize for 6918990 (example.com)...Resize complete!
59
61
  eos
60
62
 
61
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).
62
- to have_been_made
63
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823/resize?api_key=#{api_key}&client_id=#{client_key}&size_id=123")).
64
- to have_been_made
65
63
  end
66
64
 
67
65
  it "raises SystemExit when a request fails" do
68
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
69
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
70
- stub_request(:get, "https://api.digitalocean.com/droplets/100823/resize?api_key=#{api_key}&client_id=#{client_key}&size_id=123").
71
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 500, :body => '{"status":"ERROR","message":"Some error"}')
72
-
73
- @cli.options = @cli.options.merge(:size => 123)
74
- expect { @cli.resize("foo") }.to raise_error(SystemExit)
75
-
76
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).
77
- to have_been_made
78
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823/resize?api_key=#{api_key}&client_id=#{client_key}&size_id=123")).
79
- to have_been_made
66
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
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.9.2'}).
68
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
69
+
70
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/6918990/actions").
71
+ with(:body => "{\"type\":\"resize\",\"size\":\"1gb\"}",
72
+ :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'}).
73
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 500, :body => '{"status":"ERROR","message":"Some error"}')
74
+
75
+ @cli.options = @cli.options.merge(:size => '1gb')
76
+ expect { @cli.resize("example.com") }.to raise_error(SystemExit)
77
+
78
+ expect($stdout.string).to eq <<-eos
79
+ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
80
+ Queuing resize for 6918990 (example.com)...Failed to resize Droplet: Some error
81
+ eos
82
+
80
83
  end
81
84
  end
82
85
  end
@@ -5,78 +5,80 @@ describe Tugboat::CLI do
5
5
 
6
6
  describe "restarts a droplet" do
7
7
  it "with a fuzzy name" do
8
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
8
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?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.9.2'}).
10
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
10
11
 
11
- stub_request(:put, "https://api.digitalocean.com/droplets/100823/reboot?api_key=#{api_key}&client_id=#{client_key}").
12
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
12
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/6918990/actions").
13
+ with(:body => "{\"type\":\"reboot\"}",
14
+ :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'}).
15
+ to_return(:status => 200, :body => fixture('restart_response'), :headers => {})
13
16
 
14
- @cli.restart("foo")
17
+ @cli.restart("example.com")
15
18
 
16
19
  expect($stdout.string).to eq <<-eos
17
- Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 100823 (foo)
18
- Queuing restart for 100823 (foo)...done
20
+ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
21
+ Queuing restart for 6918990 (example.com)...Restart complete!
19
22
  eos
20
23
 
21
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
22
- expect(a_request(:put, "https://api.digitalocean.com/droplets/100823/reboot?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
23
24
  end
24
25
 
25
26
  it "restarts a droplet hard when the hard option is used" do
26
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
27
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
28
- stub_request(:put, "https://api.digitalocean.com/droplets/100823/power_cycle?api_key=#{api_key}&client_id=#{client_key}").
29
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
27
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
28
+ 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'}).
29
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
30
+
31
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/6918990/actions").
32
+ with(:body => "{\"type\":\"power_cycle\"}",
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'}).
34
+ to_return(:status => 200, :body => "", :headers => {})
30
35
 
31
36
  @cli.options = @cli.options.merge(:hard => true)
32
- @cli.restart("foo")
37
+ @cli.restart("example.com")
33
38
 
34
39
  expect($stdout.string).to eq <<-eos
35
- Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 100823 (foo)
36
- Queuing hard restart for 100823 (foo)...done
40
+ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
41
+ Queuing hard restart for 6918990 (example.com)...Restart complete!
37
42
  eos
38
-
39
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
40
- expect(a_request(:put, "https://api.digitalocean.com/droplets/100823/power_cycle?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
41
43
  end
42
44
 
43
45
  it "with an id" do
44
- stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
45
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
46
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
47
+ 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'}).
48
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
46
49
 
47
- stub_request(:put, "https://api.digitalocean.com/droplets/100823/reboot?api_key=#{api_key}&client_id=#{client_key}").
48
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
50
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/6918990/actions").
51
+ with(:body => "{\"type\":\"reboot\"}",
52
+ :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'}).
53
+ to_return(:status => 200, :body => fixture('restart_response'), :headers => {})
49
54
 
50
- @cli.options = @cli.options.merge(:id => droplet_id)
55
+ @cli.options = @cli.options.merge(:id => '6918990')
51
56
  @cli.restart
52
57
 
53
58
  expect($stdout.string).to eq <<-eos
54
- Droplet id provided. Finding Droplet...done\e[0m, 100823 (foo)
55
- Queuing restart for 100823 (foo)...done
59
+ Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
60
+ Queuing restart for 6918990 (example.com)...Restart complete!
56
61
  eos
57
-
58
- expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
59
- expect(a_request(:put, "https://api.digitalocean.com/droplets/100823/reboot?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
60
62
  end
61
63
 
62
64
 
63
65
  it "with a name" do
64
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
65
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
66
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
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.9.2'}).
68
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
66
69
 
67
- stub_request(:put, "https://api.digitalocean.com/droplets/100823/reboot?api_key=#{api_key}&client_id=#{client_key}").
68
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
70
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/6918990/actions").
71
+ with(:body => "{\"type\":\"reboot\"}",
72
+ :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'}).
73
+ to_return(:status => 200, :body => fixture('restart_response'), :headers => {})
69
74
 
70
- @cli.options = @cli.options.merge(:name => droplet_name)
75
+ @cli.options = @cli.options.merge(:name => 'example.com')
71
76
  @cli.restart
72
77
 
73
78
  expect($stdout.string).to eq <<-eos
74
- Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)
75
- Queuing restart for 100823 (foo)...done
79
+ Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
80
+ Queuing restart for 6918990 (example.com)...Restart complete!
76
81
  eos
77
-
78
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
79
- expect(a_request(:put, "https://api.digitalocean.com/droplets/100823/reboot?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
80
82
  end
81
83
 
82
84
  end
@@ -5,20 +5,25 @@ describe Tugboat::CLI do
5
5
 
6
6
  describe "sizes" do
7
7
  it "shows a list" do
8
- stub_request(:get, "https://api.digitalocean.com/sizes?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_sizes"))
8
+
9
+ stub_request(:get, "https://api.digitalocean.com/v2/sizes?per_page=200").
10
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
11
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_sizes"))
10
12
 
11
13
  @cli.sizes
12
14
 
13
15
  expect($stdout.string).to eq <<-eos
14
16
  Sizes:
15
- Size 1 (id: 1)
16
- Size 2 (id: 2)
17
- Size 3 (id: 3)
17
+ Disk: 20GB, Memory: 512MB (slug: 512mb)
18
+ Disk: 30GB, Memory: 1024MB (slug: 1gb)
19
+ Disk: 40GB, Memory: 2048MB (slug: 2gb)
20
+ Disk: 60GB, Memory: 4096MB (slug: 4gb)
21
+ Disk: 80GB, Memory: 8192MB (slug: 8gb)
22
+ Disk: 160GB, Memory: 16384MB (slug: 16gb)
23
+ Disk: 320GB, Memory: 32768MB (slug: 32gb)
24
+ Disk: 480GB, Memory: 49152MB (slug: 48gb)
25
+ Disk: 640GB, Memory: 65536MB (slug: 64gb)
18
26
  eos
19
-
20
- expect(a_request(:get, "https://api.digitalocean.com/sizes?api_key=#{api_key}&client_id=#{client_key}")).
21
- to have_been_made
22
27
  end
23
28
  end
24
29
  end
@@ -7,78 +7,77 @@ describe Tugboat::CLI do
7
7
 
8
8
  describe "snapshots a droplet" do
9
9
  it "with a fuzzy name" do
10
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
11
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets_inactive"))
10
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
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 => {})
12
13
 
13
- stub_request(:get, "https://api.digitalocean.com/droplets/100823/snapshot?api_key=#{api_key}&client_id=#{client_key}&name=#{snapshot_name}").
14
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
14
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/3164444/actions").
15
+ with(:body => "{\"type\":\"snapshot\",\"name\":\"foo-snapshot\"}",
16
+ :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'}).
17
+ to_return(:status => 200, :body => fixture('snapshot_response'), :headers => {})
15
18
 
16
- @cli.snapshot(snapshot_name, "foo")
19
+ @cli.snapshot(snapshot_name, 'example3.com')
17
20
 
18
21
  expect($stdout.string).to eq <<-eos
19
- Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 100823 (foo)
22
+ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
20
23
  Warning: Droplet must be in a powered off state for snapshot to be successful
21
- Queuing snapshot 'foo-snapshot' for 100823 (foo)...done
24
+ Queuing snapshot 'foo-snapshot' for 3164444 (example3.com)...Snapshot successful!
22
25
  eos
23
-
24
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
25
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823/snapshot?api_key=#{api_key}&client_id=#{client_key}&name=#{snapshot_name}")).to have_been_made
26
26
  end
27
27
 
28
28
  it "with an id" do
29
- stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
30
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet_inactive"))
29
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/3164444?per_page=200").
30
+ 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'}).
31
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet_inactive"))
31
32
 
32
- stub_request(:get, "https://api.digitalocean.com/droplets/100823/snapshot?api_key=#{api_key}&client_id=#{client_key}&name=#{snapshot_name}").
33
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
33
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/3164494/actions").
34
+ with(:body => "{\"type\":\"snapshot\",\"name\":\"foo-snapshot\"}",
35
+ :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'}).
36
+ to_return(:status => 200, :body => fixture('snapshot_response'), :headers => {})
34
37
 
35
- @cli.options = @cli.options.merge(:id => droplet_id)
38
+ @cli.options = @cli.options.merge(:id => '3164444')
36
39
  @cli.snapshot(snapshot_name)
37
40
 
38
41
  expect($stdout.string).to eq <<-eos
39
- Droplet id provided. Finding Droplet...done\e[0m, 100823 (foo)
42
+ Droplet id provided. Finding Droplet...done\e[0m, 3164494 (example.com)
40
43
  Warning: Droplet must be in a powered off state for snapshot to be successful
41
- Queuing snapshot 'foo-snapshot' for 100823 (foo)...done
44
+ Queuing snapshot 'foo-snapshot' for 3164494 (example.com)...Snapshot successful!
42
45
  eos
43
-
44
- expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
45
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823/snapshot?api_key=#{api_key}&client_id=#{client_key}&name=#{snapshot_name}")).to have_been_made
46
46
  end
47
47
 
48
48
 
49
49
  it "with a name" do
50
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
51
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets_inactive"))
50
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
51
+ 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'}).
52
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
52
53
 
53
- stub_request(:get, "https://api.digitalocean.com/droplets/100823/snapshot?api_key=#{api_key}&client_id=#{client_key}&name=#{snapshot_name}").
54
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
54
+ stub_request(:post, "https://api.digitalocean.com/v2/droplets/3164444/actions").
55
+ with(:body => "{\"type\":\"snapshot\",\"name\":\"foo-snapshot\"}",
56
+ :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'}).
57
+ to_return(:status => 200, :body => fixture('snapshot_response'), :headers => {})
55
58
 
56
- @cli.options = @cli.options.merge(:name => droplet_name)
59
+ @cli.options = @cli.options.merge(:name => 'example3.com')
57
60
  @cli.snapshot(snapshot_name)
58
61
 
59
62
  expect($stdout.string).to eq <<-eos
60
- Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)
63
+ Droplet name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
61
64
  Warning: Droplet must be in a powered off state for snapshot to be successful
62
- Queuing snapshot 'foo-snapshot' for 100823 (foo)...done
65
+ Queuing snapshot 'foo-snapshot' for 3164444 (example3.com)...Snapshot successful!
63
66
  eos
64
-
65
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
66
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823/snapshot?api_key=#{api_key}&client_id=#{client_key}&name=#{snapshot_name}")).to have_been_made
67
67
  end
68
68
 
69
- it "does not snaphshot a droplet that is active" do
70
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
71
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
69
+ it "does not snapshot a droplet that is active" do
70
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
71
+ 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'}).
72
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
72
73
 
73
- @cli.options = @cli.options.merge(:name => droplet_name)
74
+ @cli.options = @cli.options.merge(:name => 'example.com')
74
75
  expect {@cli.snapshot(snapshot_name)}.to raise_error(SystemExit)
75
76
 
76
77
  expect($stdout.string).to eq <<-eos
77
- Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)
78
+ Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
78
79
  Droplet must be off for this operation to be successful.
79
80
  eos
80
-
81
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
82
81
  end
83
82
 
84
83
  end
@@ -5,32 +5,24 @@ describe Tugboat::CLI do
5
5
 
6
6
  describe "ssh" do
7
7
  it "tries to fetch the droplet's IP from the API" do
8
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
8
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
9
9
  to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
10
- allow(Kernel).to receive(:exec)
11
-
12
- @cli.ssh("test222")
10
+ allow(Kernel).to receive(:exec).with('ssh', anything(), anything(),anything(), anything(),anything(), anything(),anything(), anything(),anything(), anything(),anything(), anything(),anything())
13
11
 
14
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).
15
- to have_been_made
12
+ @cli.ssh("example.com")
16
13
  end
17
14
 
18
15
  it "does not allow ssh into a droplet that is inactive" do
19
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
20
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets_inactive"))
21
-
16
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
17
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
22
18
  allow(Kernel).to receive(:exec)
23
19
 
24
- @cli.options = @cli.options.merge(:name => droplet_name)
25
-
26
- expect {@cli.ssh("test222")}.to raise_error(SystemExit)
20
+ expect {@cli.ssh("example3.com")}.to raise_error(SystemExit)
27
21
 
28
22
  expect($stdout.string).to eq <<-eos
29
- Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)
23
+ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 3164444 (example3.com)
30
24
  Droplet must be on for this operation to be successful.
31
25
  eos
32
-
33
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
34
26
  end
35
27
 
36
28
  end