-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
destroy and info command #91
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Tugboat | ||
module Middleware | ||
class DestroyImage < Base | ||
def call(env) | ||
ocean = env["ocean"] | ||
|
||
say "Queuing destroy image for #{env["image_id"]} #{env["image_name"]}...", nil, false | ||
|
||
req = ocean.images.delete env["image_id"] | ||
|
||
if req.status == "ERROR" | ||
say "#{req.status}: #{req.error_message}", :red | ||
exit 1 | ||
end | ||
|
||
say "done", :green | ||
|
||
@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,25 @@ | ||
module Tugboat | ||
module Middleware | ||
class InfoImage < Base | ||
def call(env) | ||
ocean = env["ocean"] | ||
|
||
req = ocean.images.show env["image_id"] | ||
|
||
if req.status == "ERROR" | ||
say "#{req.status}: #{req.error_message}", :red | ||
exit 1 | ||
end | ||
|
||
image = req.image | ||
|
||
say | ||
say "Name: #{image.name}" | ||
say "ID: #{image.id}" | ||
say "Distribution: #{image.distribution}" | ||
|
||
@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,88 @@ | ||
require 'spec_helper' | ||
|
||
describe Tugboat::CLI do | ||
include_context "spec" | ||
|
||
describe "destroy image" do | ||
it "destroys an image with a fuzzy name" do | ||
stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_images")) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
$stdin.should_receive(:gets).and_return("y") | ||
|
||
@cli.destroy_image("NLP Final") | ||
|
||
expect($stdout.string).to eq <<-eos | ||
Image fuzzy name provided. Finding image ID...done\e[0m, 478 (NLP Final)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy image for 478 (NLP Final)...done | ||
eos | ||
|
||
expect(a_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
expect(a_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
end | ||
|
||
it "destroys an image with an id" do | ||
stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
$stdin.should_receive(:gets).and_return("y") | ||
|
||
@cli.options = @cli.options.merge(:id => 478) | ||
@cli.destroy_image | ||
|
||
expect($stdout.string).to eq <<-eos | ||
Image id provided. Finding Image...done\e[0m, 478 (NLP Final)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy image for 478 (NLP Final)...done | ||
eos | ||
|
||
expect(a_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
expect(a_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
end | ||
|
||
|
||
it "destroys an image with a name" do | ||
stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_images")) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
$stdin.should_receive(:gets).and_return("y") | ||
|
||
@cli.options = @cli.options.merge(:name => "NLP Final") | ||
@cli.destroy_image | ||
|
||
expect($stdout.string).to eq <<-eos | ||
Image name provided. Finding image ID...done\e[0m, 478 (NLP Final)\nWarning! Potentially destructive action. Please confirm [y/n]: Queuing destroy image for 478 (NLP Final)...done | ||
eos | ||
|
||
expect(a_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
expect(a_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
end | ||
|
||
|
||
it "destroys an image with confirm flag set" do | ||
stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_images")) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
@cli.options = @cli.options.merge(:name => "NLP Final") | ||
@cli.options = @cli.options.merge(:confirm => true) | ||
@cli.destroy_image("NLP Final") | ||
|
||
expect($stdout.string).to eq <<-eos | ||
Image name provided. Finding image ID...done\e[0m, 478 (NLP Final)\nQueuing destroy image for 478 (NLP Final)...done | ||
eos | ||
|
||
expect(a_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
expect(a_request(:get, "https://api.digitalocean.com/images/478/destroy?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
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,61 @@ | ||
require 'spec_helper' | ||
|
||
describe Tugboat::CLI do | ||
include_context "spec" | ||
|
||
describe "show" do | ||
it "shows an image with a fuzzy name" do | ||
stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_images")) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
@cli.info_image("NLP Final") | ||
|
||
expect($stdout.string).to eq <<-eos | ||
Image fuzzy name provided. Finding image ID...done\e[0m, 478 (NLP Final)\n\nName: NLP Final\nID: 478\nDistribution: Ubuntu | ||
eos | ||
|
||
expect(a_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
expect(a_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
end | ||
|
||
it "shows an image with an id" do | ||
stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
@cli.options = @cli.options.merge(:id => 478) | ||
@cli.info_image | ||
|
||
expect($stdout.string).to eq <<-eos | ||
Image id provided. Finding Image...done\e[0m, 478 (NLP Final)\n\nName: NLP Final\nID: 478\nDistribution: Ubuntu | ||
eos | ||
|
||
expect(a_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made.times(2) | ||
end | ||
|
||
it "shows an image with a name" do | ||
stub_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_images")) | ||
|
||
stub_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}"). | ||
to_return(:status => 200, :body => fixture("show_image")) | ||
|
||
@cli.options = @cli.options.merge(:name => "NLP Final") | ||
@cli.info_image | ||
|
||
expect($stdout.string).to eq <<-eos | ||
Image name provided. Finding image ID...done\e[0m, 478 (NLP Final)\n\nName: NLP Final\nID: 478\nDistribution: Ubuntu | ||
eos | ||
|
||
expect(a_request(:get, "https://api.digitalocean.com/images/478?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
expect(a_request(:get, "https://api.digitalocean.com/images?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made | ||
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
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,8 @@ | ||
{ | ||
"image": { | ||
"distribution": "Ubuntu", | ||
"id": 478, | ||
"name": "NLP Final" | ||
}, | ||
"status": "OK" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot! 👍