Skip to content

Commit

Permalink
Merge pull request #223 from pearkes/show_private_ip_in_droplet_list
Browse files Browse the repository at this point in the history
Add specs to private ip in droplet list fix from #222
  • Loading branch information
petems committed Dec 1, 2015
2 parents 31727b8 + 5b1aaad commit 36bd049
Show file tree
Hide file tree
Showing 3 changed files with 279 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tugboat/middleware/list_droplets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def call(env)

private_addr = droplet.networks.v4.detect { |address| address.type == 'private' }
if private_addr
private_ip = ", privateip: #{private_addr.ip_address}"
private_ip = ", private_ip: #{private_addr.ip_address}"
end

if droplet.status == "active"
Expand Down
20 changes: 20 additions & 0 deletions spec/cli/droplets_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@
expect(a_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200")).to have_been_made
end

it "shows a private IP if droplet in list has private IP" 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/droplets?page=1&per_page=200").
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_private_ip"), :headers => {'Content-Type' => 'application/json'},)

@cli.droplets

expect($stdout.string).to eq <<-eos
exampleprivate.com (ip: 104.236.32.182, private_ip: 10.131.99.89, status: \e[32mactive\e[0m, region: nyc3, id: 6918990)
example2.com (ip: 104.236.32.172, status: \e[32mactive\e[0m, region: nyc3, id: 3164956)
example3.com (ip: 104.236.32.173, status: \e[31moff\e[0m, region: nyc3, id: 3164444)
eos

expect(a_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200")).to have_been_made
end

it "returns an error message when no droplets 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'}).
Expand Down
258 changes: 258 additions & 0 deletions spec/fixtures/show_droplets_private_ip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
{
"droplets": [
{
"id": 6918990,
"name": "exampleprivate.com",
"memory": 512,
"vcpus": 1,
"disk": 20,
"locked": false,
"status": "active",
"kernel": {
"id": 2233,
"name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic",
"version": "3.13.0-37-generic"
},
"created_at": "2014-11-14T16:29:21Z",
"features": [
"backups",
"ipv6",
"virtio"
],
"backup_ids": [
7938002
],
"snapshot_ids": [

],
"image": {
"id": 6918990,
"name": "14.04 x64",
"distribution": "Ubuntu",
"slug": "ubuntu-14-04-x64",
"public": true,
"regions": [
"nyc1",
"ams1",
"sfo1",
"nyc2",
"ams2",
"sgp1",
"lon1",
"nyc3",
"ams3",
"nyc3"
],
"created_at": "2014-10-17T20:24:33Z",
"min_disk_size": 20
},
"size_slug": "512mb",
"networks": {
"v4": [
{
"ip_address": "104.236.32.182",
"netmask": "255.255.192.0",
"gateway": "104.236.0.1",
"type": "public"
},
{
"ip_address": "10.131.99.89",
"netmask": "255.255.0.0",
"gateway": "10.131.0.1",
"type": "private"
}
],
"v6": [
{
"ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001",
"netmask": 64,
"gateway": "2604:A880:0800:0010:0000:0000:0000:0001",
"type": "public"
}
]
},
"region": {
"name": "New York 3",
"slug": "nyc3",
"sizes": [

],
"features": [
"virtio",
"private_networking",
"backups",
"ipv6",
"metadata"
],
"available": null
}
},
{
"id": 3164956,
"name": "example2.com",
"memory": 512,
"vcpus": 1,
"disk": 20,
"locked": false,
"status": "active",
"kernel": {
"id": 2233,
"name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic",
"version": "3.13.0-37-generic"
},
"created_at": "2014-08-14T16:29:21Z",
"features": [
"backups",
"ipv6",
"virtio"
],
"backup_ids": [
7938002
],
"snapshot_ids": [

],
"image": {
"id": 6918990,
"name": "14.04 x64",
"distribution": "Ubuntu",
"slug": "ubuntu-14-04-x64",
"public": true,
"regions": [
"nyc1",
"ams1",
"sfo1",
"nyc2",
"ams2",
"sgp1",
"lon1",
"nyc3",
"ams3",
"nyc3"
],
"created_at": "2014-10-17T20:24:33Z",
"min_disk_size": 20
},
"size_slug": "512mb",
"networks": {
"v4": [
{
"ip_address": "104.236.32.172",
"netmask": "255.255.192.0",
"gateway": "104.236.0.1",
"type": "public"
}
],
"v6": [
{
"ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001",
"netmask": 64,
"gateway": "2604:A880:0800:0010:0000:0000:0000:0001",
"type": "public"
}
]
},
"region": {
"name": "New York 3",
"slug": "nyc3",
"sizes": [

],
"features": [
"virtio",
"private_networking",
"backups",
"ipv6",
"metadata"
],
"available": null
}
},
{
"id": 3164444,
"name": "example3.com",
"memory": 512,
"vcpus": 1,
"disk": 20,
"locked": false,
"status": "off",
"kernel": {
"id": 2233,
"name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic",
"version": "3.13.0-37-generic"
},
"created_at": "2014-08-14T16:29:21Z",
"features": [
"backups",
"ipv6",
"virtio"
],
"backup_ids": [
7938002
],
"snapshot_ids": [

],
"image": {
"id": 6918990,
"name": "14.04 x64",
"distribution": "Ubuntu",
"slug": "ubuntu-14-04-x64",
"public": true,
"regions": [
"nyc1",
"ams1",
"sfo1",
"nyc2",
"ams2",
"sgp1",
"lon1",
"nyc3",
"ams3",
"nyc3"
],
"created_at": "2014-10-17T20:24:33Z",
"min_disk_size": 20
},
"size_slug": "512mb",
"networks": {
"v4": [
{
"ip_address": "104.236.32.173",
"netmask": "255.255.192.0",
"gateway": "104.236.0.1",
"type": "public"
}
],
"v6": [
{
"ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001",
"netmask": 64,
"gateway": "2604:A880:0800:0010:0000:0000:0000:0001",
"type": "public"
}
]
},
"region": {
"name": "New York 3",
"slug": "nyc3",
"sizes": [

],
"features": [
"virtio",
"private_networking",
"backups",
"ipv6",
"metadata"
],
"available": null
}
}
],
"links": {
},
"meta": {
"total": 4
}
}

0 comments on commit 36bd049

Please sign in to comment.