tugboat 1.3.1 → 2.0.0.RC1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -3,248 +3,248 @@ require 'spec_helper'
3
3
  describe Tugboat::CLI do
4
4
  include_context "spec"
5
5
 
6
- describe "show" do
6
+ describe "info" do
7
7
  it "shows 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"))
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(:get, "https://api.digitalocean.com/droplets/100823?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(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
13
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
14
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
13
15
 
14
- @cli.info("foo")
16
+ @cli.info("example.com")
15
17
 
16
18
  expect($stdout.string).to eq <<-eos
17
- Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 100823 (foo)
19
+ Droplet fuzzy name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
18
20
 
19
- Name: foo
20
- ID: 100823
21
+ Name: example.com
22
+ ID: 6918990
21
23
  Status: \e[32mactive\e[0m
22
- IP: 33.33.33.10
23
- Private IP: 10.20.30.40
24
- Region ID: 1
25
- Image ID: 420
26
- Size ID: 33
24
+ IP4: 104.131.186.241
25
+ IP6: 2604:A880:0800:0010:0000:0000:031D:2001
26
+ Region: New York 3 - nyc3
27
+ Image: 6918990 - 14.04 x64
28
+ Size: 512MB
27
29
  Backups Active: false
28
30
  eos
29
31
 
30
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
31
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
32
32
  end
33
33
 
34
34
  it "shows a droplet with an id" do
35
- stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
36
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
35
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
36
+ 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'}).
37
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
37
38
 
38
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
39
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
40
-
41
- @cli.options = @cli.options.merge(:id => droplet_id)
39
+ @cli.options = @cli.options.merge(:id => 6918990)
42
40
  @cli.info
43
41
 
44
42
  expect($stdout.string).to eq <<-eos
45
- Droplet id provided. Finding Droplet...done\e[0m, 100823 (foo)
43
+ Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
46
44
 
47
- Name: foo
48
- ID: 100823
45
+ Name: example.com
46
+ ID: 6918990
49
47
  Status: \e[32mactive\e[0m
50
- IP: 33.33.33.10
51
- Private IP: 10.20.30.40
52
- Region ID: 1
53
- Image ID: 420
54
- Size ID: 33
48
+ IP4: 104.131.186.241
49
+ IP6: 2604:A880:0800:0010:0000:0000:031D:2001
50
+ Region: New York 3 - nyc3
51
+ Image: 6918990 - 14.04 x64
52
+ Size: 512MB
55
53
  Backups Active: false
56
54
  eos
57
-
58
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
59
- expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
60
55
  end
61
56
 
62
57
  it "shows a droplet with a name" do
63
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
64
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
58
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
59
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
60
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
65
61
 
66
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
67
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
62
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
63
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
64
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
68
65
 
69
- @cli.options = @cli.options.merge(:name => droplet_name)
66
+ @cli.options = @cli.options.merge(:name => "example.com")
70
67
  @cli.info
71
68
 
72
69
  expect($stdout.string).to eq <<-eos
73
- Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)
70
+ Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
74
71
 
75
- Name: foo
76
- ID: 100823
72
+ Name: example.com
73
+ ID: 6918990
77
74
  Status: \e[32mactive\e[0m
78
- IP: 33.33.33.10
79
- Private IP: 10.20.30.40
80
- Region ID: 1
81
- Image ID: 420
82
- Size ID: 33
75
+ IP4: 104.131.186.241
76
+ IP6: 2604:A880:0800:0010:0000:0000:031D:2001
77
+ Region: New York 3 - nyc3
78
+ Image: 6918990 - 14.04 x64
79
+ Size: 512MB
83
80
  Backups Active: false
84
81
  eos
85
-
86
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
87
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
88
82
  end
89
83
 
90
84
  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"))
85
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
86
+ 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'}).
87
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
93
88
 
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"))
89
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
90
+ 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'}).
91
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
96
92
 
97
93
  $stdin.should_receive(:gets).and_return('0')
98
94
 
99
- @cli.info("test")
95
+ @cli.info("examp")
100
96
 
101
97
  expect($stdout.string).to eq <<-eos
102
98
  Droplet fuzzy name provided. Finding droplet ID...Multiple droplets found.
103
99
 
104
- 0) test222 (100823)
105
- 1) test223 (100824)
100
+ 0) example.com (6918990)
101
+ 1) example2.com (3164956)
102
+ 2) example3.com (3164444)
106
103
 
107
- Please choose a droplet: ["0", "1"]\x20
108
- Name: test222
109
- ID: 100823
104
+ Please choose a droplet: ["0", "1", "2"]\x20
105
+ Name: example.com
106
+ ID: 6918990
110
107
  Status: \e[32mactive\e[0m
111
- IP: 33.33.33.10
112
- Region ID: 1
113
- Image ID: 420
114
- Size ID: 33
108
+ IP4: 104.131.186.241
109
+ IP6: 2604:A880:0800:0010:0000:0000:031D:2001
110
+ Region: New York 3 - nyc3
111
+ Image: 6918990 - 14.04 x64
112
+ Size: 512MB
115
113
  Backups Active: false
116
114
  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
115
  end
121
116
 
122
117
  end
123
118
 
124
119
  it "shows a droplet with an id under porcelain mode" do
125
- stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
126
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
127
-
128
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
129
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
120
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
121
+ 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'}).
122
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
130
123
 
131
- @cli.options = @cli.options.merge(:id => droplet_id, :porcelain => true)
124
+ @cli.options = @cli.options.merge(:id => '6918990', :porcelain => true)
132
125
  @cli.info
133
126
 
134
127
  expect($stdout.string).to eq <<-eos
135
- name foo
136
- id 100823
128
+ name example.com
129
+ id 6918990
137
130
  status active
138
- ip 33.33.33.10
139
- private_ip 10.20.30.40
140
- region_id 1
141
- image_id 420
142
- size_id 33
131
+ ip4 104.131.186.241
132
+ ip6 2604:A880:0800:0010:0000:0000:031D:2001
133
+ region nyc3
134
+ Image 6918990
135
+ size 512mb
143
136
  backups_active false
144
137
  eos
145
-
146
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
147
- expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
148
138
  end
149
139
 
150
140
  it "shows a droplet with a name under porcelain mode" do
151
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
152
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
141
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
142
+ 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'}).
143
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
153
144
 
154
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
155
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
145
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
146
+ 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'}).
147
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
156
148
 
157
- @cli.options = @cli.options.merge(:name => droplet_name, :porcelain => true)
149
+ @cli.options = @cli.options.merge(:name => 'example.com', :porcelain => true)
158
150
  @cli.info
159
151
 
160
152
  expect($stdout.string).to eq <<-eos
161
- name foo
162
- id 100823
153
+ name example.com
154
+ id 6918990
163
155
  status active
164
- ip 33.33.33.10
165
- private_ip 10.20.30.40
166
- region_id 1
167
- image_id 420
168
- size_id 33
156
+ ip4 104.131.186.241
157
+ ip6 2604:A880:0800:0010:0000:0000:031D:2001
158
+ region nyc3
159
+ Image 6918990
160
+ size 512mb
169
161
  backups_active false
170
162
  eos
171
-
172
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
173
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
174
163
  end
175
164
 
176
165
  it "shows a droplet attribute with an id" do
177
- stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
178
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
179
-
180
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
181
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
166
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
167
+ 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'}).
168
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
182
169
 
183
- @cli.options = @cli.options.merge(:id => droplet_id, :attribute => "ip")
170
+ @cli.options = @cli.options.merge(:id => '6918990', :attribute => "ip4")
184
171
  @cli.info
185
172
 
186
173
  expect($stdout.string).to eq <<-eos
187
- Droplet id provided. Finding Droplet...done\e[0m, 100823 (foo)
188
- 33.33.33.10
174
+ Droplet id provided. Finding Droplet...done\e[0m, 6918990 (example.com)
175
+ 104.131.186.241
189
176
  eos
190
-
191
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
192
- expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
193
177
  end
194
178
 
195
179
  it "shows a droplet attribute with a name" do
196
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
197
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
180
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
181
+ 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'}).
182
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
198
183
 
199
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
200
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
184
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
185
+ 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'}).
186
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
201
187
 
202
- @cli.options = @cli.options.merge(:name => droplet_name, :attribute => "ip")
188
+ @cli.options = @cli.options.merge(:name => 'example.com', :attribute => "ip4")
203
189
  @cli.info
204
190
 
205
191
  expect($stdout.string).to eq <<-eos
206
- Droplet name provided. Finding droplet ID...done\e[0m, 100823 (foo)
207
- 33.33.33.10
192
+ Droplet name provided. Finding droplet ID...done\e[0m, 6918990 (example.com)
193
+ 104.131.186.241
208
194
  eos
209
-
210
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
211
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
212
195
  end
213
196
 
214
- it "shows a droplet attribute with an id under porcelain mode" do
215
- stub_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}").
216
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
197
+ it "gives error if invalid attribute given" do
198
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
199
+ 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'}).
200
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
217
201
 
218
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
219
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
202
+ @cli.options = @cli.options.merge(:id => 6918990, :porcelain => true, :attribute => "foo")
203
+ expect {@cli.info}.to raise_error(SystemExit)
220
204
 
221
- @cli.options = @cli.options.merge(:id => droplet_id, :porcelain => true, :attribute => "ip")
205
+ expect($stdout.string).to eq <<-eos
206
+ Invalid attribute "foo"
207
+ Provide one of the following:
208
+ name
209
+ id
210
+ status
211
+ ip4
212
+ ip6
213
+ private_ip
214
+ region
215
+ Image
216
+ size
217
+ backups_active
218
+ eos
219
+ end
220
+
221
+ it "shows a droplet attribute with an id under porcelain mode" do
222
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
223
+ 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'}).
224
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
225
+
226
+ @cli.options = @cli.options.merge(:id => '6918990', :porcelain => true, :attribute => "ip4")
222
227
  @cli.info
223
228
 
224
229
  expect($stdout.string).to eq <<-eos
225
- 33.33.33.10
230
+ 104.131.186.241
226
231
  eos
227
-
228
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
229
- expect(a_request(:get, "https://api.digitalocean.com/droplets/#{droplet_id}?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
230
232
  end
231
233
 
232
234
  it "shows a droplet attribute with a name under porcelain mode" do
233
- stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
234
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplets"))
235
-
236
- stub_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}").
237
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_droplet"))
238
-
239
- @cli.options = @cli.options.merge(:name => droplet_name, :porcelain => true, :attribute => "ip")
235
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets?per_page=200").
236
+ 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'}).
237
+ to_return(:status => 200, :body => fixture('show_droplets'), :headers => {})
238
+ stub_request(:get, "https://api.digitalocean.com/v2/droplets/6918990?per_page=200").
239
+ 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'}).
240
+ to_return(:status => 200, :body => fixture('show_droplet'), :headers => {})
241
+
242
+ @cli.options = @cli.options.merge(:name => 'example.com', :porcelain => true, :attribute => "ip4")
240
243
  @cli.info
241
244
 
242
245
  expect($stdout.string).to eq <<-eos
243
- 33.33.33.10
246
+ 104.131.186.241
244
247
  eos
245
-
246
- expect(a_request(:get, "https://api.digitalocean.com/droplets/100823?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
247
- expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
248
248
  end
249
249
 
250
250
  end
@@ -3,59 +3,146 @@ require 'spec_helper'
3
3
  describe Tugboat::CLI do
4
4
  include_context "spec"
5
5
 
6
- describe "show" do
6
+ describe "info_image" do
7
7
  it "shows an image with a fuzzy name" do
8
- stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
8
+ stub_request(:get, "https://api.digitalocean.com/v2/images?per_page=200").
9
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
10
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
10
11
 
11
- stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
12
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
12
+ stub_request(:get, "https://api.digitalocean.com/v2/images/12789325?per_page=200").
13
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
14
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_coreos_image"))
13
15
 
14
- @cli.info_image("NLP Final")
16
+ @cli.info_image("745.1.0 (alpha)")
15
17
 
16
18
  expect($stdout.string).to eq <<-eos
17
- Image fuzzy name provided. Finding image ID...done\e[0m, 478 (NLP Final)\n\nName: NLP Final\nID: 478\nDistribution: Ubuntu
18
- eos
19
+ Image fuzzy name provided. Finding image ID...done\e[0m, 12789325 (745.1.0 (alpha))
19
20
 
20
- expect(a_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
21
- expect(a_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
21
+ Name: 745.1.0 (alpha)
22
+ ID: 12789325
23
+ Distribution: CoreOS
24
+ eos
22
25
  end
23
26
 
24
27
  it "shows an image with an id" do
25
- stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
26
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
28
+ stub_request(:get, "https://api.digitalocean.com/v2/images?per_page=200").
29
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
30
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
27
31
 
28
- stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
29
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
32
+ stub_request(:get, "https://api.digitalocean.com/v2/images/12438838?per_page=200").
33
+ 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'}).
34
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_redmine_image"))
30
35
 
31
- @cli.options = @cli.options.merge(:id => 478)
36
+ @cli.options = @cli.options.merge(:id => 12438838)
32
37
  @cli.info_image
33
38
 
34
39
  expect($stdout.string).to eq <<-eos
35
- Image id provided. Finding Image...done\e[0m, 478 (NLP Final)\n\nName: NLP Final\nID: 478\nDistribution: Ubuntu
36
- eos
40
+ Image id provided. Finding Image...done\e[0m, 12438838 (Redmine on 14.04)
37
41
 
38
- expect(a_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made.times(2)
42
+ Name: Redmine on 14.04
43
+ ID: 12438838
44
+ Distribution: Ubuntu
45
+ eos
39
46
  end
40
47
 
41
48
  it "shows an image with a name" do
42
- stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}").
43
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
49
+ stub_request(:get, "https://api.digitalocean.com/v2/images?per_page=200").
50
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
51
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
44
52
 
45
- stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}").
46
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_image"))
53
+ stub_request(:get, "https://api.digitalocean.com/v2/images/12438838?per_page=200").
54
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
55
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_redmine_image"))
47
56
 
48
- @cli.options = @cli.options.merge(:name => "NLP Final")
57
+ @cli.options = @cli.options.merge(:name => "Redmine on 14.04")
49
58
  @cli.info_image
50
59
 
51
60
  expect($stdout.string).to eq <<-eos
52
- Image name provided. Finding image ID...done\e[0m, 478 (NLP Final)\n\nName: NLP Final\nID: 478\nDistribution: Ubuntu
61
+ Image name provided. Finding Image...done\e[0m, 12438838 (Redmine on 14.04)
62
+
63
+ Name: Redmine on 14.04
64
+ ID: 12438838
65
+ Distribution: Ubuntu
66
+ eos
67
+ end
68
+
69
+ it "errors if no image with matching id is found" do
70
+ stub_request(:get, "https://api.digitalocean.com/v2/images?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(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
73
+
74
+ stub_request(:get, "https://api.digitalocean.com/v2/images/123?per_page=200").
75
+ 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'}).
76
+ to_return(:status => 404, :body => fixture('not_found'), :headers => {})
77
+
78
+ @cli.options = @cli.options.merge(:id => '123')
79
+ expect {@cli.info_image}.to raise_error(SystemExit)
80
+
81
+ expect($stdout.string).to eq <<-eos
82
+ Image id provided. Finding Image...Failed to find Image: The resource you were accessing could not be found.
83
+ eos
84
+ end
85
+
86
+ it "errors if no image with matching name is found" do
87
+ stub_request(:get, "https://api.digitalocean.com/v2/images?per_page=200").
88
+ 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'}).
89
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
90
+
91
+ @cli.options = @cli.options.merge(:name => 'foobarbaz')
92
+ expect {@cli.info_image}.to raise_error(SystemExit)
93
+
94
+ expect($stdout.string).to eq <<-eos
95
+ Image name provided. Finding Image...error
96
+ Unable to find an image named 'foobarbaz'.
97
+ eos
98
+ end
99
+
100
+ it "errors if no image with matching fuzzy name is found" do
101
+ stub_request(:get, "https://api.digitalocean.com/v2/images?per_page=200").
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(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
104
+
105
+ expect {@cli.info_image("foobarbaz")}.to raise_error(SystemExit)
106
+
107
+ expect($stdout.string).to eq <<-eos
108
+ Image fuzzy name provided. Finding image ID...error
109
+ Unable to find an image named 'foobarbaz'.
53
110
  eos
111
+ end
112
+
113
+ it "allows choice of multiple images" do
114
+ stub_request(:get, "https://api.digitalocean.com/v2/images?per_page=200").
115
+ 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'}).
116
+ to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_images"))
117
+
118
+ stub_request(:get, "https://api.digitalocean.com/v2/images/9801951?per_page=200").
119
+ 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'}).
120
+ to_return(:status => 200, :body => fixture('ubuntu_image_9801951'), :headers => {})
121
+
122
+ $stdin.should_receive(:gets).and_return('0')
54
123
 
55
- expect(a_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
56
- expect(a_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
124
+ @cli.info_image("ubun")
125
+
126
+ expect($stdout.string).to eq <<-eos
127
+ Image fuzzy name provided. Finding image ID...Multiple images found.
128
+
129
+ 0) 14.10 x32 (9801951)
130
+ 1) 14.10 x64 (9801954)
131
+ 2) 12.04.5 x64 (10321756)
132
+ 3) 12.04.5 x32 (10321777)
133
+ 4) 15.04 x64 (12658446)
134
+ 5) 15.04 x32 (12660649)
135
+ 6) 14.04 x32 (12790298)
136
+ 7) 14.04 x64 (12790328)
137
+
138
+ Please choose a image: ["0", "1", "2", "3", "4", "5", "6", "7"]\x20
139
+ Name: 14.10 x32
140
+ ID: 9801951
141
+ Distribution: Ubuntu
142
+ eos
57
143
  end
58
144
 
145
+
59
146
  end
60
147
 
61
148
  end
@@ -5,18 +5,20 @@ describe Tugboat::CLI do
5
5
 
6
6
  describe "keys" do
7
7
  it "shows a list" do
8
- stub_request(:get, "https://api.digitalocean.com/ssh_keys?api_key=#{api_key}&client_id=#{client_key}").
9
- to_return(:headers => {'Content-Type' => 'application/json'}, :status => 200, :body => fixture("show_keys"))
8
+
9
+ stub_request(:get, "https://api.digitalocean.com/v2/account/keys?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(:status => 200, :body => fixture('show_keys'), :headers => {})
10
12
 
11
13
  @cli.keys
12
14
 
13
15
  expect($stdout.string).to eq <<-eos
14
16
  SSH Keys:
15
- office-imac (id: 10)
16
- macbook-air (id: 11)
17
+ Name: My SSH Public Key, (id: 512189), fingerprint: 3b:16:bf:e4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa
18
+ Name: My Other SSH Public Key, (id: 512110), fingerprint: 3b:16:bf:d4:8b:00:8b:b8:59:8c:a9:d3:f0:19:45:fa
17
19
  eos
18
20
 
19
- expect(a_request(:get, "https://api.digitalocean.com/ssh_keys?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
21
+ expect(a_request(:get, "https://api.digitalocean.com/v2/account/keys?per_page=200")).to have_been_made
20
22
  end
21
23
  end
22
24
  end