-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First step for #249 * Listing of all snapshots
- Loading branch information
Showing
7 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Tugboat | ||
module Middleware | ||
# Check if the client has set-up configuration yet. | ||
class ListSnapshots < Base | ||
def call(env) | ||
ocean = env['droplet_kit'] | ||
|
||
verify_credentials(ocean) | ||
|
||
response = ocean.snapshots.all(per_page: env['per_page']) | ||
|
||
has_one = false | ||
|
||
response.each do |snapshot| | ||
has_one = true | ||
|
||
say "#{snapshot.name} (id: #{snapshot.id}, resource_type: #{snapshot.resource_type}, created_at: #{snapshot.created_at})" | ||
end | ||
|
||
unless has_one | ||
say "You don't appear to have any snapshots.", :red | ||
end | ||
|
||
@app.call(env) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'spec_helper' | ||
|
||
describe Tugboat::CLI do | ||
include_context 'spec' | ||
|
||
describe 'snapshots' do | ||
it 'shows a list when snapshots exist' do | ||
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1'). | ||
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' }). | ||
to_return(status: 200, body: fixture('show_droplets'), headers: {}) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/v2/snapshots?page=1&per_page=20"). | ||
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'}). | ||
to_return(status: 200, body: fixture('show_snapshots'), headers: {}) | ||
|
||
expected_string = <<-eos | ||
5.10 x64 (id: 6372321, resource_type: droplet, created_at: 2014-09-26T16:40:18Z) | ||
eos | ||
|
||
expect { cli.snapshots }.to output(expected_string).to_stdout | ||
|
||
expect(a_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1')).to have_been_made.once | ||
expect(a_request(:get, 'https://api.digitalocean.com/v2/snapshots?page=1&per_page=20')).to have_been_made.once | ||
end | ||
|
||
it 'shows a message when no snapshots exist' do | ||
stub_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1'). | ||
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' }). | ||
to_return(status: 200, body: fixture('show_droplets'), headers: {}) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/v2/snapshots?page=1&per_page=20"). | ||
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'}). | ||
to_return(status: 200, body: fixture('show_snapshots_empty'), headers: {}) | ||
|
||
expected_string = <<-eos | ||
You don't appear to have any snapshots. | ||
eos | ||
|
||
expect { cli.snapshots }.to output(expected_string).to_stdout | ||
|
||
expect(a_request(:get, 'https://api.digitalocean.com/v2/droplets?page=1&per_page=1')).to have_been_made.once | ||
expect(a_request(:get, 'https://api.digitalocean.com/v2/snapshots?page=1&per_page=20')).to have_been_made.once | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"snapshots": [ | ||
{ | ||
"id": 6372321, | ||
"name": "5.10 x64", | ||
"regions": [ | ||
"nyc1", | ||
"ams1", | ||
"sfo1", | ||
"nyc2", | ||
"ams2", | ||
"sgp1", | ||
"lon1", | ||
"nyc3", | ||
"ams3", | ||
"fra1", | ||
"tor1" | ||
], | ||
"created_at": "2014-09-26T16:40:18Z", | ||
"resource_id": 2713828, | ||
"resource_type": "droplet", | ||
"min_disk_size": 20, | ||
"size_gigabytes": 1.42 | ||
} | ||
], | ||
"links": { | ||
"pages": { | ||
"last": "https://api.digitalocean.com/v2/snapshots?page=1&per_page=1" | ||
} | ||
}, | ||
"meta": { | ||
"total": 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"snapshots": [], | ||
"links": {}, | ||
"meta": { | ||
"total": 0 | ||
} | ||
} |