Skip to content

Commit 36bd049

Browse files
committed
Merge pull request #223 from pearkes/show_private_ip_in_droplet_list
Add specs to private ip in droplet list fix from #222
2 parents 31727b8 + 5b1aaad commit 36bd049

File tree

3 files changed

+279
-1
lines changed

3 files changed

+279
-1
lines changed

lib/tugboat/middleware/list_droplets.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def call(env)
1515

1616
private_addr = droplet.networks.v4.detect { |address| address.type == 'private' }
1717
if private_addr
18-
private_ip = ", privateip: #{private_addr.ip_address}"
18+
private_ip = ", private_ip: #{private_addr.ip_address}"
1919
end
2020

2121
if droplet.status == "active"

spec/cli/droplets_cli_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@
2424
expect(a_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200")).to have_been_made
2525
end
2626

27+
it "shows a private IP if droplet in list has private IP" do
28+
stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=1").
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(:status => 200, :body => fixture('show_droplets'), :headers => {})
31+
32+
stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&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(:status => 200, :body => fixture("show_droplets_private_ip"), :headers => {'Content-Type' => 'application/json'},)
35+
36+
@cli.droplets
37+
38+
expect($stdout.string).to eq <<-eos
39+
exampleprivate.com (ip: 104.236.32.182, private_ip: 10.131.99.89, status: \e[32mactive\e[0m, region: nyc3, id: 6918990)
40+
example2.com (ip: 104.236.32.172, status: \e[32mactive\e[0m, region: nyc3, id: 3164956)
41+
example3.com (ip: 104.236.32.173, status: \e[31moff\e[0m, region: nyc3, id: 3164444)
42+
eos
43+
44+
expect(a_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=200")).to have_been_made
45+
end
46+
2747
it "returns an error message when no droplets exist" do
2848
stub_request(:get, "https://api.digitalocean.com/v2/droplets?page=1&per_page=1").
2949
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'}).
Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
{
2+
"droplets": [
3+
{
4+
"id": 6918990,
5+
"name": "exampleprivate.com",
6+
"memory": 512,
7+
"vcpus": 1,
8+
"disk": 20,
9+
"locked": false,
10+
"status": "active",
11+
"kernel": {
12+
"id": 2233,
13+
"name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic",
14+
"version": "3.13.0-37-generic"
15+
},
16+
"created_at": "2014-11-14T16:29:21Z",
17+
"features": [
18+
"backups",
19+
"ipv6",
20+
"virtio"
21+
],
22+
"backup_ids": [
23+
7938002
24+
],
25+
"snapshot_ids": [
26+
27+
],
28+
"image": {
29+
"id": 6918990,
30+
"name": "14.04 x64",
31+
"distribution": "Ubuntu",
32+
"slug": "ubuntu-14-04-x64",
33+
"public": true,
34+
"regions": [
35+
"nyc1",
36+
"ams1",
37+
"sfo1",
38+
"nyc2",
39+
"ams2",
40+
"sgp1",
41+
"lon1",
42+
"nyc3",
43+
"ams3",
44+
"nyc3"
45+
],
46+
"created_at": "2014-10-17T20:24:33Z",
47+
"min_disk_size": 20
48+
},
49+
"size_slug": "512mb",
50+
"networks": {
51+
"v4": [
52+
{
53+
"ip_address": "104.236.32.182",
54+
"netmask": "255.255.192.0",
55+
"gateway": "104.236.0.1",
56+
"type": "public"
57+
},
58+
{
59+
"ip_address": "10.131.99.89",
60+
"netmask": "255.255.0.0",
61+
"gateway": "10.131.0.1",
62+
"type": "private"
63+
}
64+
],
65+
"v6": [
66+
{
67+
"ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001",
68+
"netmask": 64,
69+
"gateway": "2604:A880:0800:0010:0000:0000:0000:0001",
70+
"type": "public"
71+
}
72+
]
73+
},
74+
"region": {
75+
"name": "New York 3",
76+
"slug": "nyc3",
77+
"sizes": [
78+
79+
],
80+
"features": [
81+
"virtio",
82+
"private_networking",
83+
"backups",
84+
"ipv6",
85+
"metadata"
86+
],
87+
"available": null
88+
}
89+
},
90+
{
91+
"id": 3164956,
92+
"name": "example2.com",
93+
"memory": 512,
94+
"vcpus": 1,
95+
"disk": 20,
96+
"locked": false,
97+
"status": "active",
98+
"kernel": {
99+
"id": 2233,
100+
"name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic",
101+
"version": "3.13.0-37-generic"
102+
},
103+
"created_at": "2014-08-14T16:29:21Z",
104+
"features": [
105+
"backups",
106+
"ipv6",
107+
"virtio"
108+
],
109+
"backup_ids": [
110+
7938002
111+
],
112+
"snapshot_ids": [
113+
114+
],
115+
"image": {
116+
"id": 6918990,
117+
"name": "14.04 x64",
118+
"distribution": "Ubuntu",
119+
"slug": "ubuntu-14-04-x64",
120+
"public": true,
121+
"regions": [
122+
"nyc1",
123+
"ams1",
124+
"sfo1",
125+
"nyc2",
126+
"ams2",
127+
"sgp1",
128+
"lon1",
129+
"nyc3",
130+
"ams3",
131+
"nyc3"
132+
],
133+
"created_at": "2014-10-17T20:24:33Z",
134+
"min_disk_size": 20
135+
},
136+
"size_slug": "512mb",
137+
"networks": {
138+
"v4": [
139+
{
140+
"ip_address": "104.236.32.172",
141+
"netmask": "255.255.192.0",
142+
"gateway": "104.236.0.1",
143+
"type": "public"
144+
}
145+
],
146+
"v6": [
147+
{
148+
"ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001",
149+
"netmask": 64,
150+
"gateway": "2604:A880:0800:0010:0000:0000:0000:0001",
151+
"type": "public"
152+
}
153+
]
154+
},
155+
"region": {
156+
"name": "New York 3",
157+
"slug": "nyc3",
158+
"sizes": [
159+
160+
],
161+
"features": [
162+
"virtio",
163+
"private_networking",
164+
"backups",
165+
"ipv6",
166+
"metadata"
167+
],
168+
"available": null
169+
}
170+
},
171+
{
172+
"id": 3164444,
173+
"name": "example3.com",
174+
"memory": 512,
175+
"vcpus": 1,
176+
"disk": 20,
177+
"locked": false,
178+
"status": "off",
179+
"kernel": {
180+
"id": 2233,
181+
"name": "Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic",
182+
"version": "3.13.0-37-generic"
183+
},
184+
"created_at": "2014-08-14T16:29:21Z",
185+
"features": [
186+
"backups",
187+
"ipv6",
188+
"virtio"
189+
],
190+
"backup_ids": [
191+
7938002
192+
],
193+
"snapshot_ids": [
194+
195+
],
196+
"image": {
197+
"id": 6918990,
198+
"name": "14.04 x64",
199+
"distribution": "Ubuntu",
200+
"slug": "ubuntu-14-04-x64",
201+
"public": true,
202+
"regions": [
203+
"nyc1",
204+
"ams1",
205+
"sfo1",
206+
"nyc2",
207+
"ams2",
208+
"sgp1",
209+
"lon1",
210+
"nyc3",
211+
"ams3",
212+
"nyc3"
213+
],
214+
"created_at": "2014-10-17T20:24:33Z",
215+
"min_disk_size": 20
216+
},
217+
"size_slug": "512mb",
218+
"networks": {
219+
"v4": [
220+
{
221+
"ip_address": "104.236.32.173",
222+
"netmask": "255.255.192.0",
223+
"gateway": "104.236.0.1",
224+
"type": "public"
225+
}
226+
],
227+
"v6": [
228+
{
229+
"ip_address": "2604:A880:0800:0010:0000:0000:02DD:4001",
230+
"netmask": 64,
231+
"gateway": "2604:A880:0800:0010:0000:0000:0000:0001",
232+
"type": "public"
233+
}
234+
]
235+
},
236+
"region": {
237+
"name": "New York 3",
238+
"slug": "nyc3",
239+
"sizes": [
240+
241+
],
242+
"features": [
243+
"virtio",
244+
"private_networking",
245+
"backups",
246+
"ipv6",
247+
"metadata"
248+
],
249+
"available": null
250+
}
251+
}
252+
],
253+
"links": {
254+
},
255+
"meta": {
256+
"total": 4
257+
}
258+
}

0 commit comments

Comments
 (0)